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

[tracker] [tests] Python test suite reliability: striving for non-flaky, parallelizable, random-orderable tests. #12191

Open
6 of 11 tasks
jayaddison opened this issue Mar 23, 2024 · 1 comment
Labels
help wanted python Pull requests that update Python code type:task type:tests

Comments

@jayaddison
Copy link
Contributor

jayaddison commented Mar 23, 2024

This is an umbrella issue to track progress making the Sphinx test suite reliable. That means:

  • No flaky tests.
  • Tests can run in parallel.
  • Tests are independent of each other.

Regarding the last item: test independence is important to ensure that each test is checking the behaviours it claims to, and does not inadvertently rely on the side-effects of some other test. Similarly, a test must not begin failing if any other test is run before it -- if it does, that could mean (but does not definitely mean) that the application's behaviour itself may vary based on the order in which code is evaluated.

It might seem like there are a large number of items here! However, please bear in mind that we have a total of more than 2000 individual pytest test cases that run.

Test flakiness

Test parallelization

Test independence

@jayaddison jayaddison added type:tests python Pull requests that update Python code labels Mar 23, 2024
@picnixz picnixz pinned this issue Mar 23, 2024
@picnixz picnixz changed the title [meta-issue] [tests] Python test suite reliability: striving for non-flaky, parallelizable, random-orderable tests. [tracker] [tests] Python test suite reliability: striving for non-flaky, parallelizable, random-orderable tests. Mar 23, 2024
@AA-Turner
Copy link
Member

We should aim to make the test roots source directories read-only. This would help reliability as we can assert that state does not change. It also would speed up the tests as we can avoid copying every test root tree.

A patch to track tests that add new files to source directories (~15 currently)

Subject: [PATCH] Track new files in test srcdirs
---
Index: sphinx/testing/fixtures.py
<+>UTF-8
===================================================================
diff --git a/sphinx/testing/fixtures.py b/sphinx/testing/fixtures.py
--- a/sphinx/testing/fixtures.py	(revision c0681ed22dd28c4009a352aaa453c204cdadfbbd)
+++ b/sphinx/testing/fixtures.py	(revision 6a733c958d017877a86b7619559a38e5d13cd19d)
@@ -153,8 +153,20 @@
     """
     args, kwargs = app_params
     app_ = make_app(*args, **kwargs)
+    old = frozenset(app_.srcdir.rglob('*'))
+
     yield app_
 
+    new = old - set(app_.srcdir.rglob('*'))
+    new = new - frozenset(app_.srcdir.joinpath('_build').rglob('*'))
+    new = frozenset(p for p in new if p.is_file() and p.parent.name != '__pycache__')
+    if new:
+        from pathlib import Path
+        path_san = app_.srcdir.as_posix().replace('/', '~').replace(':', '')
+        filename = f'added~{path_san}~{hash(new)}.txt'
+        Path(filename).write_text('\n'.join(sorted(map(str, new))), encoding='utf-8')
+
     print('# testroot:', kwargs.get('testroot', 'root'))
     print('# builder:', app_.builder.name)
     print('# srcdir:', app_.srcdir)

Something else to investigate is rolling back sys.modules, as well as sys.path.

A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted python Pull requests that update Python code type:task type:tests
Projects
None yet
Development

No branches or pull requests

4 participants
@AA-Turner @picnixz @jayaddison and others