- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
[BUG] Tests have global side-effects. #11285
Comments
I noticed that while running `pytest --random` and the extension should wipe CNAME file if a configuration changes and it should not be created. Related: sphinx-doc#11285
I noticed that while running `pytest --random` and the extension should wipe CNAME file if a configuration changes and it should not be created. Related: sphinx-doc#11285
I noticed that while running `pytest --random` and the extension should wipe CNAME file if a configuration changes and it should not be created. Related: sphinx-doc#11285
Some tests need app.builder.build_all in order to have complete rebuild. Related: sphinx-doc#11285.
Some tests need app.builder.build_all in order to have complete rebuild. Related: sphinx-doc#11285.
Use `freshenv` argument and remove `outdir` for one tests as the previous one can leave an unexpected leftover. Related: sphinx-doc#11285.
In - kwargs['srcdir'] = srcdir = sphinx_test_tempdir / kwargs.get('srcdir', testroot)
+ kwargs['srcdir'] = srcdir = util.path(tmp_path) / kwargs.get('srcdir', testroot) using Pytest's A |
That's a pretty significant slow-down I would say. Next week, I can finish fixes for
|
I am moving my reply to #11293 (comment) here:
I have the following suggestions in that direction:
|
The tests modify source files (index.rst), that is not restored and thus another test can reach a modified source file and it leads to unexpected test results. Related: sphinx-doc#11285
The tests modify source files (index.rst), that is not restored and thus another test can reach a modified source file and it leads to unexpected test results. Related: sphinx-doc#11285
The test fails with --random due to leftovers in app.outdir location. Related: sphinx-doc#11285
Related: sphinx-doc#11285 Co-authored-by: Jean-François B <2589111+jfbu@users.noreply.github.com>
Just a few comments about different levels of independence when it comes to tests:
I tried to enable Feel free to comment my thoughts and what are realistic goals we can have? |
I was trying to fix #10193 and when I wanted to only run the autodoc test suite. HOWEVER, I observed that tests actually FAIL because of side-effects way more than what I expected. I also tried using As such, the next I'll be focusing is fixing the test suite. I'll try the following:
|
So, I found a possible side-effect culprit when implementing #11964. I actually put my modules at the same level as the conf.py file because I didn't want to bother with a package. However ! it appears that it caused some weird side-effect. I verified locally by running all tests in I'll continue investigating but I'll first try to fix #11941. EDIT: I fixed #11941, so I'll start investigating this one tomorrow. |
I'm facing the same issue that autodoc-related tests succeed if run alone in isolation but fail as soon as multiple tests are run simultaneously. I attempted to debug the issue for several hours with no success. The error only occurs when multiple tests document the same python module/class. When each test operates on its individual python test data/module, everything is fine. |
I am working in a reimplementation and I haven't pushed the new changes yet. I think what I did should be fine so please wait for a few weeks time until I have more time! |
Describe the bug
While implementing some feature, I wanted to test the latter by selectively running some tests but I found that the tests are not executed in an isolated context, namely they have undesirable side-effects.
A simple way to see that is by manually running the following tests:
The first test succeeds but the second one fails with the following assertion error:
The reason is that, in the first test, the documenter being used is a
ModuleDocumenter
for tests/roots/test-ext-autodoc/target/typed_vars.py. In particular, when the documenter documents its members, the annotations of theAlias
class is NOT updated using the annotations of theDerived
andClass
class. By addingafter
sphinx/sphinx/ext/autodoc/__init__.py
Lines 877 to 880 in 669bcc0
then the output of the first command is:
However, if we do the same thing when running the second command, we get the following output:
In other words
test_autoattribute_typed_variable_in_alias
is polluting the global context oftest_autodoc_typed_instance_variables
! The reason is that theAttributeDocumenter
used to testtest_autoattribute_typed_variable_in_alias
fires autodoc events which cause the annotations of the parent object (namelyAlias
) to be updated. SinceAlias
is an alias, they will propagate toDerived
, and this is why when documentingDerived
intest_autodoc_typed_instance_variables
by aClassDocumenter
, we end up having more annotations than really needed.Other side-effects can be seen when simply running this following command:
python -m tox -e py310 -- tests/test_ext_autodoc*
I think that we need to make sure that each test does not collide with another one and not assume that such test is executed after or before another one. This can be extremely helpful when we simply want to run separate tests (perhaps this can actually be done easily when setting up pytest?).
How to Reproduce
Compare the output of
with the output of
Environment Information
Sphinx extensions
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: