Skip to content

Run tests in parallel with pytest-xdist (v2) - #9945

Open
akx wants to merge 7 commits into
python-pillow:mainfrom
akx:pytest-xdist-v2
Open

Run tests in parallel with pytest-xdist (v2)#9945
akx wants to merge 7 commits into
python-pillow:mainfrom
akx:pytest-xdist-v2

Conversation

@akx

@akx akx commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Closes #9342 (supersedes it).
Closes #9933 (this contains those commits).
Related to #9944 (comment).

This PR:

  • takes the pytest-xdist learnings and changes from Run tests in parallel with pytest-xdist #9342 with some adjustments
  • replaces the leak tests' peak RSS computation with current RSS; peak RSS simply isn't the accurate measurement for leaks. This requires a new (well-known, common) dependency, psutil, since resource.getrusage() can't.
    • It should be noted that technically leak tests could now be enabled on Windows, since psutil can measure things there too, but there's probably no point.
  • From Improve test stability #9933, disabling leak tests on PyPy, since PyPy may decide to JIT compile code it deems hot, and that will remain in RSS anyway, and would look like a leak.
  • From Improve test stability #9933, reducing the test_empty_image size for the "tall" case to 0 × 10,000,000 instead of 0 × 100,000,000, since a 0 × H size image still requires allocating H row pointers. This gets rid of the transient timeout for that test -- my guess is that sometimes allocating that much space (with zeroing, so the OS can't just allocate pages for later touching!) takes a bit of time.

akx and others added 7 commits September 2, 2026 18:05
* pytest-xdist is only needed by the invocations that actually run in parallel
* --numprocesses=logical additionally needs psutil

This follows test-arrow style.
Let the tests and test-xdist extras be the single source of truth for
tests/distributed-tests extras.
Pass the options at each call site rather than putting them in addopts, so pytests may also run without test-xdist.

REVERSE dropped because xdist runs tests in arbitrary order anyhow. That matrix entry still does PYTHONOPTIMIZE=1.

Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
* ru_maxrss never falls, so leak tests were measuring occasional transient
  spikes, not true leaks. Instead, for leak tests we now read the current
  RSS, which falls (to a degree, depending on system allocator strategy)
  when memory is released, and also doesn't depend on the process's past.
* The tests' limits were adjusted based on empirical measurements.
* psutil is brought in by the test-xdist extra from before, but also
  test-leaks.
The tall case still needs to allocate the row-pointer table `im->image`, which is still roughly 700 megabytes, which evidently can be slow
@akx

akx commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

cc @hugovk, this is based on your xdist work :)

@akx
akx marked this pull request as ready for review September 2, 2026 18:26
@radarhere

Copy link
Copy Markdown
Member

For future reference, I think this could have been a PR for hugovk's fork, to update the existing PR, rather than a brand new PR for this repository.

@akx

akx commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

@radarhere Thanks. Yes, that had been my initial plan. I decided against that because #9342 has conflicts against main at present which would've required resolving by hand, and for a cleaner branch history. I took care to retain authorship/co-authorship in the commits, of course.

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.

3 participants