Skip to content

Workaround for #3742 #3751

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

Merged
merged 2 commits into from
Aug 2, 2018
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
4 changes: 3 additions & 1 deletion src/_pytest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,8 @@ def collect(self):
self.trace.root.indent -= 1

def _collect(self, arg):
from _pytest.python import Package

names = self._parsearg(arg)
argpath = names.pop(0)
paths = []
Expand All @@ -503,7 +505,7 @@ def _collect(self, arg):
root = self._node_cache[pkginit]
else:
col = root._collectfile(pkginit)
if col:
if col and isinstance(col, Package):
Copy link
Member

Choose a reason for hiding this comment

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

this one is part of creating headaches - in future we def need to sort that out

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, I'm hoping @jonozzz can come up with a good solution to this. 😁

Copy link

Choose a reason for hiding this comment

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

Totally agree, this needs a major rework, at least the code that went into main.py.

root = col[0]
self._node_cache[root.fspath] = root

Expand Down
10 changes: 10 additions & 0 deletions testing/example_scripts/fixtures/custom_item/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pytest


class CustomItem(pytest.Item, pytest.File):
def runtest(self):
pass


def pytest_collect_file(path, parent):
return CustomItem(path, parent)
Empty file.
2 changes: 2 additions & 0 deletions testing/example_scripts/fixtures/custom_item/foo/test_foo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def test():
pass
5 changes: 5 additions & 0 deletions testing/python/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,11 @@ def test_package(one):
reprec = testdir.inline_run()
reprec.assertoutcome(passed=2)

def test_collect_custom_items(self, testdir):
testdir.copy_example("fixtures/custom_item")
result = testdir.runpytest("foo")
result.stdout.fnmatch_lines("*passed*")


class TestAutouseDiscovery(object):
@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion testing/test_collection.py
Original file line number Diff line number Diff line change
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.parent is None
assert col.parent.parent is None
for col in col.listchain():
assert col.config is config

Expand Down