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):