Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions _pytest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,16 @@ def __init__(self, fspath, parent=None, config=None, session=None):
super(FSCollector, self).__init__(name, parent, config, session)
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):
relpath = self.fspath.relto(self.config.rootdir)

if not relpath:
relpath = self._check_initialpaths_for_relpath()
if os.sep != nodes.SEP:
relpath = relpath.replace(os.sep, nodes.SEP)
return relpath
Expand Down
1 change: 1 addition & 0 deletions changelog/2775.bugfix
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 3 additions & 1 deletion testing/acceptance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,10 @@ def join_pythonpath(*dirs):
for p in search_path:
monkeypatch.syspath_prepend(p)

os.chdir('world')
# 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
result.stdout.fnmatch_lines([
"*test_hello.py::test_hello*PASSED",
Expand Down