Skip to content

pytester: avoid unraisableexception gc collects in inline runs to speed up test suite #13525

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

Merged
merged 2 commits into from
Jun 16, 2025

Conversation

bluetech
Copy link
Member

@bluetech bluetech commented Jun 16, 2025

This is an alternative to #13513. I had to change some tests to run in a subprocess and tweak them a bit to make it work.

Fixes #13482.

Closes #13513.

bluetech and others added 2 commits June 16, 2025 21:43
…ed up test suite

Because `pytester.runpytest()` executes the full session cycle (including
`pytest_unconfigure`), it was calling `gc.collect()` in a loop multiple
times—even for small, fast tests. This significantly increased the total
test suite runtime.

To optimize performance, disable the gc runs in inline pytester runs
entirely, matching the behavior before pytest-dev#12958.

Locally the test suite runtime improved dramatically, dropping from 425s
to 160s.

Fixes pytest-dev#13482.

Co-authored-by: Bruno Oliveira <[email protected]>
@nicoddemus nicoddemus added skip news used on prs to opt out of the changelog requirement backport 8.4.x apply to PRs at any point; backports the changes to the 8.4.x branch labels Jun 16, 2025
Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@nicoddemus nicoddemus merged commit 391324e into pytest-dev:main Jun 16, 2025
29 of 31 checks passed
Copy link

patchback bot commented Jun 16, 2025

Backport to 8.4.x: 💚 backport PR created

✅ Backport PR branch: patchback/backports/8.4.x/391324e13a6589f5d824d053240d4b9a4139a115/pr-13525

Backported as #13526

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Jun 16, 2025
…ed up test suite (#13525)

Because `pytester.runpytest()` executes the full session cycle (including
`pytest_unconfigure`), it was calling `gc.collect()` in a loop multiple
times—even for small, fast tests. This significantly increased the total
test suite runtime.

To optimize performance, disable the gc runs in inline pytester runs
entirely, matching the behavior before #12958.

Locally the test suite runtime improved dramatically, dropping from 425s
to 160s.

Fixes #13482.

Co-authored-by: Bruno Oliveira <[email protected]>
(cherry picked from commit 391324e)
nicoddemus added a commit that referenced this pull request Jun 16, 2025
…ed up test suite (#13525) (#13526)

Because `pytester.runpytest()` executes the full session cycle (including
`pytest_unconfigure`), it was calling `gc.collect()` in a loop multiple
times—even for small, fast tests. This significantly increased the total
test suite runtime.

To optimize performance, disable the gc runs in inline pytester runs
entirely, matching the behavior before #12958.

Locally the test suite runtime improved dramatically, dropping from 425s
to 160s.

Fixes #13482.


(cherry picked from commit 391324e)

Co-authored-by: Ran Benita <[email protected]>
Co-authored-by: Bruno Oliveira <[email protected]>
@bluetech bluetech deleted the pytester-no-gc-collects branch June 18, 2025 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 8.4.x apply to PRs at any point; backports the changes to the 8.4.x branch skip news used on prs to opt out of the changelog requirement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[self-tests] test time degradation
2 participants