Fix test collection from packages mixed with directories. #3768 and #3789#3802
Fix test collection from packages mixed with directories. #3768 and #3789#3802nicoddemus merged 3 commits intopytest-dev:masterfrom
Conversation
| return Module(path, parent) | ||
|
|
||
|
|
||
| def pytest_ignore_collect(path, config): |
There was a problem hiding this comment.
Yeah this does not really seem necessary, main.pytest_ignore_collect already seems to do the exactly same thing anyway.
There was a problem hiding this comment.
Initially I copy/pasted the Package class from Session because they both serve very similar functions, and then realized not everything was needed.
| return path in self.session._initialpaths | ||
|
|
||
| def collect(self): | ||
| # XXX: HACK! |
There was a problem hiding this comment.
Strange, I expect main.pytest_ignore_collect to handle this properly already:
Lines 261 to 284 in 4d8903f
If pytest_ignore_collect sees the same path twice, it should ignore the collection when see the path the second time, which would not trigger a new Package item to be collected.
There was a problem hiding this comment.
The problem is it sees that some modules were already "collected" (at Session level) via the recurse() method. Then when the package goes and tries to collect its children and turn them into nodes it can't because they look like duplicates. Wrong! My first reaction was to try to stop marking them as duplicates at Session level, but everything is so tangled up that I can't find a cleaner way.
|
|
||
|
|
||
| def test_package_with_modules(testdir): | ||
| """ |
There was a problem hiding this comment.
Just FYI, you could have created the actual files in testing/example_scripts and copied the whole directory here like the code above this function does.
The idea is that it is easier to execute the test using pytest as normal during testing/debugging. 😉
This is fine as is, just thought I would mention this for the future. 👍
|
LGTM! Took the liberty of committing the missing changelog entries. 👍 |
This removes the hack added in pytest-dev#3802.
This removes the hack added in pytest-dev#3802. Adjusts test: - it appears to not have been changed to 7 intentionally. - removes XXX comment, likely not relevant anymore since 6dac774.
This removes the hack added in pytest-dev#3802. Adjusts test: - it appears to not have been changed to 7 intentionally. - removes XXX comment, likely not relevant anymore since 6dac774. Backport of e041823 (pytest-dev#4241) from features.
This removes the hack added in pytest-dev#3802. Adjusts test: - it appears to not have been changed to 7 intentionally. - removes XXX comment, likely not relevant anymore since 6dac774. Backport of e041823 (pytest-dev#4241) from features.
This removes the hack added in pytest-dev#3802. Adjusts test: - it appears to not have been changed to 7 intentionally. - removes XXX comment, likely not relevant anymore since 6dac774. Backport of e041823 (pytest-dev#4241) from features.
The 3.7.x releases seem to suffer from a regression in tests collection that affects our linting process. It may have been fixed upstream already [1]. Freezing requirement to latest 3.6.x for now. [1] pytest-dev/pytest#3802
This should fix the issue but I still can't find a better fix. See the comment in the code.
What happens is: the files and directories are marked as duplicates when the Session starts collection even though they're not turned into nodes right away (the package nodes will do that later). Ideally is that when Session finds a Package it should stop recursing and move on.