Skip to content

Conversation

@aIbrahiim
Copy link
Contributor

@aIbrahiim aIbrahiim commented Nov 18, 2025

Fixes: #36222

Performance Impact:

Before

The workflow python_tests.yml was taking: 1h 12m

After

this PR The same workflow completes faster, around: 38m
and windows test took around 31 minutes.

Python tests after enhancements: https://github.com/apache/beam/actions/runs/19496095132/job/55798555053

Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

@aIbrahiim aIbrahiim force-pushed the 36222-enhance-python-tests branch from 8c499bd to 7d1bed6 Compare November 19, 2025 09:17
@aIbrahiim aIbrahiim marked this pull request as ready for review November 19, 2025 10:01
@aIbrahiim
Copy link
Contributor Author

@damccorm

@github-actions
Copy link
Contributor

Assigning reviewers:

R: @claudevdm for label python.

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@claudevdm
Copy link
Collaborator

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a significant performance improvement for local test runs by making expensive cleanup operations conditional. The changes in conftest.py add new pytest options to control this behavior, enabling faster local development cycles while ensuring thorough cleanup in CI environments. The implementation is solid. My review includes a few suggestions for further improving code quality and performance, such as moving local imports to the top level for PEP 8 compliance, removing a redundant import, and caching a computed value to avoid redundant calculations.

@aIbrahiim aIbrahiim requested a review from claudevdm November 20, 2025 09:54
@github-actions
Copy link
Contributor

R: @damccorm for final approval


# Force garbage collection to clean up any lingering resources
gc.collect()
if enable_cleanup:
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a little confused - how does this speed up our CI tests? Won't the behavior in CI be the exact same since enable_cleanup will evaluate to True?

Copy link
Contributor Author

@aIbrahiim aIbrahiim Nov 21, 2025

Choose a reason for hiding this comment

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

The thing is as discussed in the issue here, the ensure_clean_state adds significant overhead (~100ms/test). While we need this strict isolation in CI to prevent flakiness (hence enable_cleanup is True), it makes running tests locally very painful and this pr implements the suggested interim solution by keeping the strict cleanup in CI (so CI remains stable) while disabling it by default locally so it can iterate more quickly.

Copy link
Contributor

Choose a reason for hiding this comment

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

The 0.1 s overhead comes from here:

https://github.com/apache/beam/pull/35889/files#diff-76dd9e3509f907a47fc83cfd5094ffdfeed3101f73ac31bfffe113605aef0b46R135

I feel skeptical about using busy wait to solve issues in general. I would suggest revert ensure_clean_state and enhance_mock_stability fixtures or move then to per-test-class based (if possible)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I agree, I'd like to at least try that and try to understand where the core problem is coming from.

If it does reduce stability, I think we can take this as a temporary measure, but with the goal of getting rid of it

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python Unit Tests is getting much slower since 2.67.0

4 participants