pytest_ignore_collect applies to all directories collected afterwards? #2016
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_test.py are both
platform darwin -- Python 2.7.10, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
I've observed this on Linux, and Mac.
The text was updated successfully, but these errors were encountered:
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.
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
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.