Skip to content

pytest_ignore_collect documentation is misleading #12383

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

Closed
mgorny opened this issue May 28, 2024 · 2 comments · Fixed by #12385
Closed

pytest_ignore_collect documentation is misleading #12383

mgorny opened this issue May 28, 2024 · 2 comments · Fixed by #12385

Comments

@mgorny
Copy link
Contributor

mgorny commented May 28, 2024

I'm reporting this as a bug because I've hit this multiple times in the wild in a variety of packages implementing pytest_ignore_collect in conftest.py.

The documentation for pytest_ignore_collect states:

Return True to prevent considering this path for collection.

This hook is consulted for all files and directories prior to calling more specific hooks.

Stops at first non-None result, see firstresult: stop at first non-None result.
(https://pytest.org/en/latest/reference/reference.html#std-hook-pytest_ignore_collect)

While this isn't incorrect, it's misleading. A lot of implementations I've seen assume they're supposed to return False for paths that are not to be ignored. In fact, I didn't realize that returning None was the right thing to do, unless I've found this bit in the changelog:

If after updating to this version you see that your norecursedirs setting is not being respected, it means that a conftest or a plugin you use has a bad pytest_ignore_collect implementation. Most likely, your hook returns False for paths it does not want to ignore, which ends the processing and doesn’t allow other plugins, including pytest itself, to ignore the path. The fix is to return None instead of False for paths your hook doesn’t want to ignore.
(https://pytest.org/en/latest/changelog.html#id141)

Could you please improve the documentation for pytest_ignore_collect to make it clear that normally True or None should be returned? This is especially problematic since returning False makes --ignore silently ignored.

mgorny added a commit to mgorny/typeguard that referenced this issue May 28, 2024
Fix `pytest_ignore_collect` hook implementation to return `None`
rather than `False` when the path ought not to be ignored.  This is
necessary to enable the default pytest implementation of
`pytest_ignore_collect()` to be used.  Otherwise, the default rules
are never applied and e.g. `--ignore` does not work.

I've also reported pytest-dev/pytest#12383
about the misleading documentation.
mgorny added a commit to mgorny/transitions that referenced this issue May 28, 2024
Fix `pytest_ignore_collect` hook implementation to return `None`
rather than `False` when the path ought not to be ignored.  This is
necessary to enable the default pytest implementation of
`pytest_ignore_collect()` to be used.  Otherwise, the default rules
are never applied and e.g. `--ignore` does not work.

I've also reported pytest-dev/pytest#12383
about the misleading documentation.
aleneum pushed a commit to pytransitions/transitions that referenced this issue May 28, 2024
Fix `pytest_ignore_collect` hook implementation to return `None`
rather than `False` when the path ought not to be ignored.  This is
necessary to enable the default pytest implementation of
`pytest_ignore_collect()` to be used.  Otherwise, the default rules
are never applied and e.g. `--ignore` does not work.

I've also reported pytest-dev/pytest#12383
about the misleading documentation.
nicoddemus added a commit that referenced this issue May 28, 2024
nicoddemus added a commit that referenced this issue May 28, 2024
@mgorny
Copy link
Contributor Author

mgorny commented May 28, 2024

Thanks! Could you also make it clear that "other plugins" include "built-in" pytest behavior?

@nicoddemus
Copy link
Member

I'm short on time, but feel free to open a PR with any other suggestions. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants