Skip to content

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

Open

Description

@jayaddison

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

Activity

  1. added
    python
    on Mar 23, 2024
  2. pinned this issue on Mar 23, 2024
  3. 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.[/+] on Mar 23, 2024
  4. AA-Turner commented on Aug 12, 2024

    @AA-Turner
    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

  5. unpinned this issue on Jan 31, 2025
  6. AA-Turner commented on Jan 31, 2025

    @AA-Turner
    Member

    With pytest-randomly installed, I get around 40 test failures, so there is still work to be done.

  7. AA-Turner commented on Feb 7, 2025

    @AA-Turner
    Member

    Tests now run in parallel with pytest-xdist on Ubuntu (#13287)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedpythontype:tasktype:tests

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions