Workaround for #3742#3751
Conversation
|
This patch fixes the test and breaks another test: diff --git a/src/_pytest/main.py b/src/_pytest/main.py
index 9599fa16..1aee4bfd 100644
--- a/src/_pytest/main.py
+++ b/src/_pytest/main.py
@@ -482,6 +482,7 @@ class Session(nodes.FSCollector):
self.trace.root.indent -= 1
def _collect(self, arg):
+ from _pytest.python import Package
names = self._parsearg(arg)
argpath = names.pop(0)
paths = []
@@ -503,7 +504,7 @@ class Session(nodes.FSCollector):
root = self._node_cache[pkginit]
else:
col = root._collectfile(pkginit)
- if col:
+ if col and isinstance(col, Package):
root = col[0]
self._node_cache[root.fspath] = rootWith the above patch, all tests pass except for this one: But this test has been changed in c02e8d8 as part of the package-scope fixtures support. For the record the patch above feels like a hack, but I don't have time today to investigate this further. I would appreciate further suggestions here, and if someone finds a proper solution feel free to push to this branch. I would like to get |
As discussed in pytest-dev#3751, this feels like a hack, pushing it only so we can see how it fares on CI and if there are better solutions out there
|
Decided to push the patch above so we can see how it fares under CI and gather feedback. Unless someone comes up with a better solution I'm considering releasing this fix as it is, at least until we have some time to work on a long term solution. |
|
I've started looking at this issue today. I applied that patch and it does seem to fix it, however it'll skip the init.py files (tested with flake8 only). It does look like a hack and I'll see if there's a better fix. |
|
Thanks for the feedback @jonozzz! |
|
@jonozzz i beleive the deeper issue comes from packags being collected on the same level as their modules and then dancing a dance around the collectors - a package should be collected from the fspath of a folder its not yet clear how to reintegrate that propperly |
|
Also need to check if this fixes #3749 |
3617f1e to
8c9efd8
Compare
|
@RonnyPfannschmidt, you marked |
|
yikes, my bad |
|
I guess we can merge this once CI passes? We definitely should investigate a better solution though. |
|
@RonnyPfannschmidt want to merge this? |
|
@nicoddemus seems that it doesn't work for pytest-asyncio. |
|
@cybergrind this one does not even try to sort out that issue - #3754 does |
| else: | ||
| col = root._collectfile(pkginit) | ||
| if col: | ||
| if col and isinstance(col, Package): |
There was a problem hiding this comment.
this one is part of creating headaches - in future we def need to sort that out
There was a problem hiding this comment.
Sure, I'm hoping @jonozzz can come up with a good solution to this. 😁
There was a problem hiding this comment.
Totally agree, this needs a major rework, at least the code that went into main.py.
|
Oh, just read to message about async_generator and scrolled down to possible patch. Will be more careful next time |
This was missing from PR #3751
|
We were bitten by the bug reported in #3742, but the fix has led to a new issue: scientific-python/pytest-doctestplus#22. I haven't done enough investigation to determine if there's a workaround on our end, but I just wanted to report it here in case anyone else is experiencing similar problems as of |
As of pytest-dev/pytest#3751, pytest will insist on importing all files it runs flake8 on. This fails in sconsUtils with an: ImportError: lsst.sconsUtils cannot be imported outside an scons script sconsUtils should still be checked for flake8 compliance by Travis.
I did not have time to investigate the issue yet, but took a few minutes to produce a failing test for #3742.
At first I'm not sure how to fix the regression, so I would appreciate suggestions here.
cc @jonozzz