Skip to content
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

main: move norecursedir check to main's pytest_ignore_collect #11082

Merged
merged 1 commit into from
Jun 6, 2023

Conversation

bluetech
Copy link
Member

@bluetech bluetech commented Jun 5, 2023

Fix #11081

Copy link
Member

@RonnyPfannschmidt RonnyPfannschmidt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, this also brings the implementation and the config for it back together

@bluetech bluetech merged commit 32de8e2 into pytest-dev:main Jun 6, 2023
25 checks passed
@bluetech bluetech deleted the norecursedir-in-hook branch June 6, 2023 09:44
@pllim
Copy link
Contributor

pllim commented Jun 6, 2023

Hi. I suspect this might have broken our test collection downstream at https://github.com/astropy/astropy . I see that it is collecting stuff that we explicitly ignored in setup.cfg like this:

[tool:pytest]
norecursedirs =
    "astropy[\/]extern"

Despite that directive, I see:

../../.tox/py311-test-devinfra/lib/python3.11/site-packages/astropy/extern/configobj/configobj.py F
../../.tox/py311-test-devinfra/lib/python3.11/site-packages/astropy/extern/configobj/validate.py F

Is there some changes I need to do downstream to account for this new pytest behavior? Thanks!

Failed log: https://github.com/astropy/astropy/actions/runs/5191708098/jobs/9359883509
pytest-7.4.0.dev118+g1a175390

Last success log: https://github.com/astropy/astropy/actions/runs/5173838762/jobs/9319503854
pytest-7.4.0.dev109+ge1204e1e

@bluetech
Copy link
Member Author

bluetech commented Jun 7, 2023

Thanks for testing pytest main @pllim, it helps a lot.

I don't have time to confirm this ATM, but this is almost certainly due to a plugin which "overrides" pytest_ignore_collect. I didn't find one in the astropy repo, but I did find a couple in the astropy organization:

To explain a bit, pytest_ignore_collect is a firstresult=True hook, which means that the first plugin which returns a non-None result decides the outcome (it is still possible to override using "hook wrappers" but that's not the case here).

The pytest-filter-subpackage impl seems OK to me, it either returns True (want to ignore) or None (don't decide).

The pytest-doctestplus impl however, does return False at the end, which means it explicitly "takes over" and asks not to ignore the path without consulting further plugins, in addition to tryfirst=True, which means it runs first.

So I believe that if you change this line to return None (or just remove it) it will fix the issue:

https://github.com/astropy/pytest-doctestplus/blob/deff8fd34bba614141d5cb34c349d54c29a3c394/pytest_doctestplus/plugin.py#L557

Note that it will change the behavior such that pytest's builtin ignore logic will now run, when it didn't previously. If that's a problem, the only fix is to just copy over the norecursedir logic from pytest.


If you can confirm the above that'd be great, I think it will be a good change to make regardless. However, I'll be taking a look at how plugins at large implement pytest_ignore_collect and if it looks like it will cause enough breakage then we can just revert it.

@pllim
Copy link
Contributor

pllim commented Jun 7, 2023

Thank you very much for the thorough analysis and recommendation, @bluetech ! I think your proposed solution looks very promising over at scientific-python/pytest-doctestplus#201 . 😺

@bluetech
Copy link
Member Author

I'll be taking a look at how plugins at large implement pytest_ignore_collect and if it looks like it will cause enough breakage then we can just revert it.

Did this now. Out of the ~700 plugins I have checked out locally, 11 implement pytest_ignore_collect, 1 implements incorrectly (2 if including pytest-doctestplus).

I also did a github search, there aren't many hits, but I'd say it's 10%-20% incorrect implementations.

Overall my impression is that the breakage won't be wide-spread. The breakage will be visible and the fix is backward compatible - no compat issues. In addition to the fact that it is already subtlety broken.

So I think we shouldn't revert. I will however add a note to the changelog entry about this.

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 this pull request may close these issues.

Move norecursedir check to the pytest_ignore_collect hook
3 participants