You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
pytest 8.0.1 regression: setup_module is not run with --doctest-modules #12011
plugin: doctestsrelated to the doctests builtin plugintype: bugproblem that needs to be addressedtype: regressionindicates a problem that was introduced in a release which was working previously
Thanks, I can reproduce. Bisected to a6851e3, which is unexpected, but I confirmed that it's the culprit. Interestingly, it does not reproduce in main. I will check what's going on.
parsefactories returns early if it had already seen an object.
The python Module has the same module object as the DoctestModule.
The python Module is collected after the DoctestModule.
The python Module patches the module object with fixtures, but now the patching is not effective -- parsefactories already ran on the object before it was patched.
Why a6851e3 revealed the issue? Because that bug caused the python Module to (wrongly) be collected before the DoctestModule.
Why it doesn't happen in main? Because c8792bd replaced the patching with directly registering the fixtures, making this a non-issue.
Possible solutions
Backport c8792bd to 8.0.x. Should be fine but a bit risky for a backport.
Reorder the python and doctest plugins such that pytest hooks run before doctest hooks. Should be fine (IMO an improvement) but risky - will cause python tests to be executed before doctests (in the same file), not sure which other effects it might have.
More localized version of the previous solution - add trylast=True to doctest's pytest_collect_file hookimpl. Same risk.
Since this is fixed in main, just release 8.1.0 in lieu of a pytest 8.0.2.
I am leaning towards solution 1 but happy to hear other opinions or ideas.
IMHO it is OK to hold this a bit and release 8.1.0 soonish, something like:
Release 8.0.2 in 2 weeks or so.
Release 8.1.0 about 1 week or so later.
I understand the frustration of having something working in 8.0.0, then 8.0.1 (a bugfix), breaks that use case for you in 8.0.1, and then maintainers telling you that you have to wait for 8.1.0 to get back what was working in 8.0.0.
I'm not so keen of implementing quick solutions in 8.0.x, specially if they have the potential of introducing other subtle problems.
If the above is not good enough, I would go with 4) then and release 8.1.0 next.
plugin: doctestsrelated to the doctests builtin plugintype: bugproblem that needs to be addressedtype: regressionindicates a problem that was introduced in a release which was working previously
Activity
bluetech commentedon Feb 19, 2024
Thanks, I can reproduce. Bisected to a6851e3, which is unexpected, but I confirmed that it's the culprit. Interestingly, it does not reproduce in main. I will check what's going on.
bluetech commentedon Feb 19, 2024
Analysis
The reason this happens:
parsefactorieson the module object.parsefactoriesreturns early if it had already seen an object.Modulehas the same module object as theDoctestModule.Moduleis collected after theDoctestModule.Modulepatches the module object with fixtures, but now the patching is not effective --parsefactoriesalready ran on the object before it was patched.Why a6851e3 revealed the issue? Because that bug caused the python
Moduleto (wrongly) be collected before theDoctestModule.Why it doesn't happen in main? Because c8792bd replaced the patching with directly registering the fixtures, making this a non-issue.
Possible solutions
Backport c8792bd to 8.0.x. Should be fine but a bit risky for a backport.
Reorder the
pythonanddoctestplugins such thatpytesthooks run beforedoctesthooks. Should be fine (IMO an improvement) but risky - will cause python tests to be executed before doctests (in the same file), not sure which other effects it might have.More localized version of the previous solution - add
trylast=Truetodoctest'spytest_collect_filehookimpl. Same risk.Since this is fixed in main, just release 8.1.0 in lieu of a pytest 8.0.2.
I am leaning towards solution 1 but happy to hear other opinions or ideas.
nicoddemus commentedon Feb 19, 2024
Thanks @bluetech for the quick analysis.
IMHO it is OK to hold this a bit and release 8.1.0 soonish, something like:
I understand the frustration of having something working in 8.0.0, then 8.0.1 (a bugfix), breaks that use case for you in 8.0.1, and then maintainers telling you that you have to wait for 8.1.0 to get back what was working in 8.0.0.
I'm not so keen of implementing quick solutions in 8.0.x, specially if they have the potential of introducing other subtle problems.
If the above is not good enough, I would go with 4) then and release 8.1.0 next.
lesteve commentedon Feb 20, 2024
Personally, I think this is completely fine to wait for 8.1.0.
This may also be an occasion for us to replace the few instances of
setup_modulewe still have by module-level fixtures.bluetech commentedon Feb 20, 2024
OK, let's wait for 8.1.0 roughly by @nicoddemus's suggested schedule.
I'll submit a regression test against main, and add a changelog that this bug is fixed, which will be included in the 8.1.0 release notes.
testing: add a regression test for `setup_module` + `--doctest-modules`
bluetech commentedon Mar 3, 2024
pytest 8.1.0 is now released.
lesteve commentedon Mar 4, 2024
Thanks for the follow-up! I confirm that this has been fixed in 8.1.0.
testing: add a regression test for `setup_module` + `--doctest-modules`