-
Notifications
You must be signed in to change notification settings - Fork 4.4k
enhance python tests #36852
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
base: master
Are you sure you want to change the base?
enhance python tests #36852
Conversation
8c499bd to
7d1bed6
Compare
|
Assigning reviewers: R: @claudevdm for label python. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
|
/gemini review |
There was a problem hiding this 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.
|
R: @damccorm for final approval |
|
|
||
| # Force garbage collection to clean up any lingering resources | ||
| gc.collect() | ||
| if enable_cleanup: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
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)
There was a problem hiding this comment.
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
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:
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, commentfixes #<ISSUE NUMBER>instead.CHANGES.mdwith noteworthy changes.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)
See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.