From 40eed363e8c0b699d71509ec4cd8ebfb05af954d Mon Sep 17 00:00:00 2001 From: holger krekel Date: Mon, 28 Jul 2014 12:07:15 +0200 Subject: [PATCH] fix issue544 by only removing "@NUM" at the end of a part (parts are separated by "::") and if the part has an .py extension. --HG-- branch : fix_initial_parsing --- CHANGELOG | 2 ++ _pytest/config.py | 10 +++++++--- testing/test_parseopt.py | 13 +++++++++++-- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index cd7ec0ca5..ac2a6e686 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -12,6 +12,8 @@ NEXT - fix issue with detecting conftest files if the arguments contain "::" node id specifications (copy pasted from "-v" output) +- fix issue544 by only removing "@NUM" at the end of "::" separated parts + and if the part has an ".py" extension 2.6 ----------------------------------- diff --git a/_pytest/config.py b/_pytest/config.py index 80a0c2c26..0b04ff1cc 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -863,9 +863,13 @@ def getcfg(args, inibasenames): def node_with_line_number(string): - split = string.split('[') - split[0] = re.sub(r'@\d+', '', split[0]) - return '['.join(split) + newparts = [] + for part in string.split("::"): + m = re.match(r'.*\.py@\d+$', part) + if m is not None: + part = part[:part.rfind("@")] + newparts.append(part) + return "::".join(newparts) def setns(obj, dic): diff --git a/testing/test_parseopt.py b/testing/test_parseopt.py index 2e19a90f4..360bbd13b 100644 --- a/testing/test_parseopt.py +++ b/testing/test_parseopt.py @@ -146,8 +146,17 @@ class TestParser: assert args.S == False def test_parse_removes_line_number_from_positional_arguments(self, parser): - args = parser.parse(['path@2::func', 'path2@5::func2[param with @]']) - assert getattr(args, parseopt.FILE_OR_DIR) == ['path::func', 'path2::func2[param with @]'] + args = parser.parse(['path.txt@2::item', + 'path2.py::func2[param with .py@123]', + 'path.py@123', + 'hello/path.py@123', + ]) + assert getattr(args, parseopt.FILE_OR_DIR) == [ + 'path.txt@2::item', + 'path2.py::func2[param with .py@123]', + 'path.py', + 'hello/path.py', + ] def test_parse_defaultgetter(self): def defaultget(option):