Skip to content

Commit

Permalink
Fix handling of collect_ignore from parent conftest
Browse files Browse the repository at this point in the history
`_collectfile` should be called on files only.

Fixes pytest-dev#4592.
  • Loading branch information
blueyed committed Feb 8, 2019
1 parent ea73246 commit ad4e9c9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/_pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,11 +642,12 @@ def collect(self):
):
continue

if path.isdir() and path.join("__init__.py").check(file=1):
pkg_prefixes.add(path)

for x in self._collectfile(path):
yield x
if path.isdir():
if path.join("__init__.py").check(file=1):
pkg_prefixes.add(path)
else:
for x in self._collectfile(path):
yield x


def _get_xunit_setup_teardown(holder, attr_name, param_obj=None):
Expand Down
13 changes: 13 additions & 0 deletions testing/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1144,3 +1144,16 @@ def test_nodeid(request):
]
)
assert result.ret == 0


def test_collectignore_via_conftest(testdir, monkeypatch):
"""collect_ignore in parent conftest skips importing child (issue #4592)."""
tests = testdir.mkpydir("tests")
tests.ensure("conftest.py").write("collect_ignore = ['ignore_me']")

ignore_me = tests.mkdir("ignore_me")
ignore_me.ensure("__init__.py")
ignore_me.ensure("conftest.py").write("assert 0, 'should_not_be_called'")

result = testdir.runpytest()
assert result.ret == EXIT_NOTESTSCOLLECTED

0 comments on commit ad4e9c9

Please sign in to comment.