Skip to content

Commit

Permalink
Add regression tests for __init__.py breakage
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile committed Nov 15, 2019
1 parent 176c777 commit 4e0f992
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Daniel Hahler
Daniel Nuri
Daniel Wandschneider
Danielle Jenkins
Daniil Galiev
Dave Hunt
David Díaz-Barquero
David Mohr
Expand Down
1 change: 1 addition & 0 deletions changelog/6194.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix incorrect discovery of non-test ``__init__.py`` files.
1 change: 1 addition & 0 deletions changelog/6197.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Revert "The first test in a package (``__init__.py``) marked with ``@pytest.mark.skip`` is now correctly skipped.".
21 changes: 21 additions & 0 deletions testing/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1257,3 +1257,24 @@ def test_collector_respects_tbstyle(testdir):
"*= 1 error in *",
]
)


def test_does_not_eagerly_collect_packages(testdir):
testdir.makepyfile("def test(): pass")
pydir = testdir.mkpydir("foopkg")
pydir.join("__init__.py").write("assert False")
result = testdir.runpytest()
assert result.ret == ExitCode.OK


def test_does_not_put_src_on_path(testdir):
# `src` is not on sys.path so it should not be importable
testdir.tmpdir.join("src/nope/__init__.py").ensure()
testdir.makepyfile(
"import pytest\n"
"def test():\n"
" with pytest.raises(ImportError):\n"
" import nope\n"
)
result = testdir.runpytest()
assert result.ret == ExitCode.OK

0 comments on commit 4e0f992

Please sign in to comment.