-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pytest_ignore_collect applies to all directories collected afterwards? #2016
Comments
In my experience, other pytest hooks apply to subdirectories only, not um sibling directories? |
The docs for
IMHO nothing there hints that it only applies for subdirectories of
Could you point other hooks which exhibit this behavior? TBH I'm not sure it is worth changing this because it would break existing plugins and that can be circumvented easily on the hook's code. |
Thanks, Bruno- The docs say for conftest say "local conftest.py plugins contain directory-specific hook implementations", which implies to me that conftest.py hooks operate on a specific directory, rather than the whole py.test process. ( http://pytest.org/2.2.4/plugins.html#conftest-py-local-per-directory-plugins). However, I see this now: "Session and test running activities will invoke all hooks defined in conftest.py files closer to the root of the filesystem". I suppose that this implies that other hooks are invoked differently? Maybe as they are discovered?
pytest_collect_file and pytest_itemcollected both operate on subdirectories, not sibling directories. Another facet of this oddity - If the directory looks like this-
The tests in child0 are run, but those in childa and childb are not. I feel like either |
Actually, I think that this may be a bug. I think that the cache here: Line 584 in 8639bf7
|
When I disabled the cache this issue was fixed and no tests failed. Furthermore, pytest tests took the same amount of time! I see that the cache was added in commit 3de715ec13a7c80b2, but there is no linked issue so I don't know if there was a specific performance target that was intended. |
Hi @d-b-w, sorry for the silence on this.
I think the wording here can be improved. What pytest does is that contains for each path a list of active I created a similar structure:
If I execute I will continue investigating... thanks for the patience on this! |
I think I now understand what's going on. You may have noticed that one of the things remove_mods = pm._conftest_plugins.difference(my_conftestmodules)
if remove_mods:
# one or more conftests are not in use at this fspath
proxy = FSHookProxy(fspath, pm, remove_mods)
else:
# all plugis are active for this fspath
proxy = self.config.hook The problem lies with the "complete proxy" of the Using the example similar to the above:
def _recurse(self, path):
ihook = self.gethookproxy(path.dirpath())
if ihook.pytest_ignore_collect(path=path, config=self.config):
return
for pat in self._norecursepatterns:
if path.check(fnmatch=pat):
return False
ihook = self.gethookproxy(path)
ihook.pytest_collect_directory(path=path, parent=self)
return True
I think the solution to this is the one you proposed on the mailing list:
This is simple to implement and I already have a working prototype. |
I put a pytest_ignore_collect() in a conftest.py. From the documentation, I had expected it to apply to all subdirectories of the one in which the conftest.py resides. However, it also prevented collection of files that were not in subdirectories!
I have this directory structure:
demo_parent/childa/conftest.py
demo_parent/childa/demo_test.py
demo_parent/childb/demo_test.py
demo_test.py are both
def test(): pass
. When I adddef pytest_ignore_collect(path, config): return True
to the conftest.py, neither of the tests are executed! I would have expected childb/demo_test.py to run.platform darwin -- Python 2.7.10, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
plugins: hypothesis-3.4.0, cov-2.2.1, faulthandler-1.3.0, xdist-1.14
also:
execnet==1.4.1
hypothesis==3.4.0
coverage==4.0.3
I've observed this on Linux, and Mac.
The text was updated successfully, but these errors were encountered: