Merged in fix_initial_parsing (pull request #186)

Fix issue544 and fix another issue with parsing ``::``
This commit is contained in:
Anatoly Bubenkov 2014-07-28 14:16:02 +02:00
commit 8ff8dd3ae9
4 changed files with 45 additions and 5 deletions

View File

@ -11,6 +11,11 @@ NEXT
- fix integration of pytest with unittest.mock.patch decorator when - fix integration of pytest with unittest.mock.patch decorator when
it uses the "new" argument. Thanks Nicolas Delaby for test and PR. it uses the "new" argument. Thanks Nicolas Delaby for test and PR.
- 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 2.6
----------------------------------- -----------------------------------

View File

@ -485,6 +485,11 @@ class Conftest(object):
testpaths = namespace.file_or_dir testpaths = namespace.file_or_dir
foundanchor = False foundanchor = False
for path in testpaths: for path in testpaths:
path = str(path)
# remove node-id syntax
i = path.find("::")
if i != -1:
path = path[:i]
anchor = current.join(path, abs=1) anchor = current.join(path, abs=1)
if exists(anchor): # we found some file object if exists(anchor): # we found some file object
self._try_load_conftest(anchor) self._try_load_conftest(anchor)
@ -857,10 +862,11 @@ def getcfg(args, inibasenames):
return {} return {}
rex_pyat = re.compile(r'(.*\.py)@\d+$')
def node_with_line_number(string): def node_with_line_number(string):
split = string.split('[') return "::".join(rex_pyat.sub(lambda m: m.group(1), part)
split[0] = re.sub(r'@\d+', '', split[0]) for part in string.split("::"))
return '['.join(split)
def setns(obj, dic): def setns(obj, dic):

View File

@ -237,3 +237,21 @@ def test_fixture_dependency(testdir, monkeypatch):
""")) """))
result = testdir.runpytest("sub") result = testdir.runpytest("sub")
result.stdout.fnmatch_lines(["*1 passed*"]) result.stdout.fnmatch_lines(["*1 passed*"])
def test_conftest_found_with_double_dash(testdir):
sub = testdir.mkdir("sub")
sub.join("conftest.py").write(py.std.textwrap.dedent("""
def pytest_addoption(parser):
parser.addoption("--hello-world", action="store_true")
"""))
p = sub.join("test_hello.py")
p.write(py.std.textwrap.dedent("""
import pytest
def test_hello(found):
assert found == 1
"""))
result = testdir.runpytest(str(p) + "@2::test_hello", "-h")
result.stdout.fnmatch_lines("""
*--hello-world*
""")

View File

@ -146,8 +146,19 @@ class TestParser:
assert args.S == False assert args.S == False
def test_parse_removes_line_number_from_positional_arguments(self, parser): def test_parse_removes_line_number_from_positional_arguments(self, parser):
args = parser.parse(['path@2::func', 'path2@5::func2[param with @]']) args = parser.parse(['path.txt@2::item',
assert getattr(args, parseopt.FILE_OR_DIR) == ['path::func', 'path2::func2[param with @]'] 'path2.py::func2[param with .py@123]',
'path.py@123',
'hello/path.py@123',
])
# we only remove "@NUM" syntax for .py files which are currently
# the only ones which can produce it.
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 test_parse_defaultgetter(self):
def defaultget(option): def defaultget(option):