Merge pull request #2776 from cryporchild/fix-missing-nodeid-with-pyargs
Fix #2775 - running pytest with "--pyargs" will result in Items with …
This commit is contained in:
commit
259b86b6ab
|
@ -521,8 +521,16 @@ class FSCollector(Collector):
|
||||||
super(FSCollector, self).__init__(name, parent, config, session)
|
super(FSCollector, self).__init__(name, parent, config, session)
|
||||||
self.fspath = fspath
|
self.fspath = fspath
|
||||||
|
|
||||||
|
def _check_initialpaths_for_relpath(self):
|
||||||
|
for initialpath in self.session._initialpaths:
|
||||||
|
if self.fspath.common(initialpath) == initialpath:
|
||||||
|
return self.fspath.relto(initialpath.dirname)
|
||||||
|
|
||||||
def _makeid(self):
|
def _makeid(self):
|
||||||
relpath = self.fspath.relto(self.config.rootdir)
|
relpath = self.fspath.relto(self.config.rootdir)
|
||||||
|
|
||||||
|
if not relpath:
|
||||||
|
relpath = self._check_initialpaths_for_relpath()
|
||||||
if os.sep != nodes.SEP:
|
if os.sep != nodes.SEP:
|
||||||
relpath = relpath.replace(os.sep, nodes.SEP)
|
relpath = relpath.replace(os.sep, nodes.SEP)
|
||||||
return relpath
|
return relpath
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fix the bug where running pytest with "--pyargs" will result in Items with empty "parent.nodeid" if run from a different root directory.
|
|
@ -624,8 +624,10 @@ class TestInvocationVariants(object):
|
||||||
for p in search_path:
|
for p in search_path:
|
||||||
monkeypatch.syspath_prepend(p)
|
monkeypatch.syspath_prepend(p)
|
||||||
|
|
||||||
|
os.chdir('world')
|
||||||
# mixed module and filenames:
|
# mixed module and filenames:
|
||||||
result = testdir.runpytest("--pyargs", "-v", "ns_pkg.hello", "world/ns_pkg")
|
result = testdir.runpytest("--pyargs", "-v", "ns_pkg.hello", "ns_pkg/world")
|
||||||
|
testdir.chdir()
|
||||||
assert result.ret == 0
|
assert result.ret == 0
|
||||||
result.stdout.fnmatch_lines([
|
result.stdout.fnmatch_lines([
|
||||||
"*test_hello.py::test_hello*PASSED",
|
"*test_hello.py::test_hello*PASSED",
|
||||||
|
|
Loading…
Reference in New Issue