Merged in fix_initial_parsing (pull request #186)
Fix issue544 and fix another issue with parsing ``::``
This commit is contained in:
commit
8ff8dd3ae9
|
@ -11,6 +11,11 @@ NEXT
|
|||
- fix integration of pytest with unittest.mock.patch decorator when
|
||||
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
|
||||
-----------------------------------
|
||||
|
|
|
@ -485,6 +485,11 @@ class Conftest(object):
|
|||
testpaths = namespace.file_or_dir
|
||||
foundanchor = False
|
||||
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)
|
||||
if exists(anchor): # we found some file object
|
||||
self._try_load_conftest(anchor)
|
||||
|
@ -857,10 +862,11 @@ def getcfg(args, inibasenames):
|
|||
return {}
|
||||
|
||||
|
||||
rex_pyat = re.compile(r'(.*\.py)@\d+$')
|
||||
|
||||
def node_with_line_number(string):
|
||||
split = string.split('[')
|
||||
split[0] = re.sub(r'@\d+', '', split[0])
|
||||
return '['.join(split)
|
||||
return "::".join(rex_pyat.sub(lambda m: m.group(1), part)
|
||||
for part in string.split("::"))
|
||||
|
||||
|
||||
def setns(obj, dic):
|
||||
|
|
|
@ -237,3 +237,21 @@ def test_fixture_dependency(testdir, monkeypatch):
|
|||
"""))
|
||||
result = testdir.runpytest("sub")
|
||||
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*
|
||||
""")
|
||||
|
|
|
@ -146,8 +146,19 @@ 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',
|
||||
])
|
||||
# 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 defaultget(option):
|
||||
|
|
Loading…
Reference in New Issue