damccorm commented on code in PR #36852:
URL: https://github.com/apache/beam/pull/36852#discussion_r2550483656
##########
sdks/python/conftest.py:
##########
@@ -101,56 +110,86 @@ def configure_beam_rpc_timeouts():
print("Successfully configured Beam RPC timeouts")
+def _running_in_ci():
+ """Returns True if running in a CI environment."""
+ return (
+ os.getenv('GITHUB_ACTIONS') == 'true' or
+ os.getenv('CI') == 'true' or
+ os.getenv('CONTINUOUS_INTEGRATION') == 'true'
+ )
+
+
+def _should_enable_test_cleanup(config):
+ """Returns True if expensive cleanup operations should run.
+
+ Result is cached on config object to avoid re-computation per test.
+ """
+ if hasattr(config, '_should_enable_test_cleanup_result'):
+ return config._should_enable_test_cleanup_result
+
+ if config.getoption('--enable-test-cleanup'):
+ result = True
+ reason = "enabled via --enable-test-cleanup"
+ else:
+ if _running_in_ci():
+ result = True
+ reason = "CI detected"
+ else:
+ result = False
+ reason = "local development"
+
+ # Log once per session
+ if not hasattr(config, '_cleanup_decision_logged'):
+ print(f"\n[Test Cleanup] Enabled: {result} ({reason})")
+ config._cleanup_decision_logged = True
+
+ config._should_enable_test_cleanup_result = result
+ return result
+
+
@pytest.fixture(autouse=True)
-def ensure_clean_state():
+def ensure_clean_state(request):
"""
- Ensure clean state before each test
- to prevent cross-test contamination.
+ Ensures clean state between tests to prevent contamination.
+
+ Expensive operations (sleeps, extra GC) only run in CI or when
+ explicitly enabled to keep local tests fast.
"""
- import gc
- import threading
- import time
+ enable_cleanup = _should_enable_test_cleanup(request.config)
- # Force garbage collection to clean up any lingering resources
- gc.collect()
+ if enable_cleanup:
Review Comment:
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
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]