Fix problems with running tests in package __init__ files (#4046)#4285
Merged
nicoddemus merged 5 commits intopytest-dev:masterfrom Nov 2, 2018
kchmck:fix-4046
Merged
Fix problems with running tests in package __init__ files (#4046)#4285nicoddemus merged 5 commits intopytest-dev:masterfrom kchmck:fix-4046
__init__ files (#4046)#4285nicoddemus merged 5 commits intopytest-dev:masterfrom
kchmck:fix-4046
Conversation
blueyed
reviewed
Nov 1, 2018
src/_pytest/main.py
Outdated
| # actually yielded up to higher collection layers, so | ||
| # remove it to allow collection by later package | ||
| # traversal. | ||
| pm._duplicatepaths.discard(pkginit) |
Contributor
Contributor
|
Created a backport for master: #4286 |
Contributor
|
Cool! |
Contributor
|
Cherry-pick e041823, please. |
Contributor
Author
|
Alright, I've updated on top of e041823 |
blueyed
approved these changes
Nov 1, 2018
Codecov Report
@@ Coverage Diff @@
## master #4285 +/- ##
==========================================
+ Coverage 95.65% 95.87% +0.21%
==========================================
Files 109 109
Lines 24630 24639 +9
Branches 2396 2395 -1
==========================================
+ Hits 23560 23622 +62
+ Misses 759 721 -38
+ Partials 311 296 -15
Continue to review full report at Codecov.
|
Contributor
|
Great work, thanks! |
nicoddemus
approved these changes
Nov 2, 2018
Member
|
Great work guys, thanks! |
Contributor
Author
|
Awesome, thanks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes some behavior changes that were introduced in 3.7.0, detailed by #4046.
If you have a directory structure like
then prior to 3.7.0 you could run
pytest mypackagefrom the project directory, and it would pick up all the tests in__init__.pyandmymodule.py. After 3.7.0 the tests in__init__.pystarted being ignored.There was a partial fix for this in #3872, but it only works if the project directory and not the package directory is passed as the argument (commit 8485081 adds an example failing test for this.)
This PR seems to fix that and the other issue in #4046. I'm pretty sure the changes here aren't ideal and should probably be cleaned up by someone more familiar with the codebase, but hopefully this can at least serve as a starting point for the fixes.
The issue with
__init__.pybeing ignored seems to stem from it being added to the duplicate paths set when it's visited in the root traversal loop, then when it's visited by the directory collection loop it gets ignored as a duplicate even though it was never checked for tests. Removing it from the duplicate set as a fix causes an additional issue of a duplicate nested package being created, which I also added a special-case fix for.The issue with all package files being collected when only
__init__.pywas specified (test in 3f07f7e) appears to stem from__init__.pybeing treated as aPackage(that gets traversed) when it should be treated as aModule.With these changes, all the existing tests except one pass (commit 28f4155). The test failure seems legitimate to me, though, because it wasn't counting the package created by the
__init__file. Please let me know if I'm interpreting that wrong.