Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #3751 #3798

Merged
merged 3 commits into from Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/_pytest/main.py
Expand Up @@ -505,8 +505,9 @@ def _collect(self, arg):
root = self._node_cache[pkginit]
else:
col = root._collectfile(pkginit)
if col and isinstance(col, Package):
root = col[0]
if col:
if isinstance(col[0], Package):
root = col[0]
self._node_cache[root.fspath] = root

# If it's a directory argument, recurse and look for any Subpackages.
Expand Down
2 changes: 1 addition & 1 deletion testing/test_collection.py
Expand Up @@ -647,7 +647,7 @@ def test_pkgfile(self, testdir):
col = testdir.getnode(config, x)
assert isinstance(col, pytest.Module)
assert col.name == "x.py"
assert col.parent.parent is None
assert col.parent.parent.parent is None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets please add add comment here to explain the nesting since it is a tad confusing as of now

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Probably checking the name of each parent will also help clarifying things. 👍

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's pretty simple, it's basically testing to see that the Session's parent is None, which should always be and the nodes have been correctly nested. For a more visual example:

tmpdir
 \- subdir
     \- __init__.py
     \- x.py


Session<>
   ^
   | (parent)
Package<subdir>
   ^
   | (parent)
Module<x>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the ASCII diagram could be added to the test's docstring?

for col in col.listchain():
assert col.config is config

Expand Down