This is an automated email from the ASF dual-hosted git repository.
damccorm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git
The following commit(s) were added to refs/heads/master by this push:
new f9f13c331dd enhance python tests (#36852)
f9f13c331dd is described below
commit f9f13c331dd3ede9829f7ffef69d39eb50fe5537
Author: Abdelrahman Ibrahim <[email protected]>
AuthorDate: Mon Nov 24 21:13:31 2025 +0200
enhance python tests (#36852)
* make test cleanup conditional to fix performance regression
* fixed PEP 8 violations and optimize test cleanup
* Change cleanup fixtures to class scope to reduce test overhead
---
sdks/python/conftest.py | 34 ++++++++++++++++------------------
1 file changed, 16 insertions(+), 18 deletions(-)
diff --git a/sdks/python/conftest.py b/sdks/python/conftest.py
index 855af55911a..683bd433e8a 100644
--- a/sdks/python/conftest.py
+++ b/sdks/python/conftest.py
@@ -17,8 +17,11 @@
"""Pytest configuration and custom hooks."""
+import gc
import os
import sys
+import threading
+import time
from types import SimpleNamespace
import pytest
@@ -101,55 +104,50 @@ def configure_beam_rpc_timeouts():
print("Successfully configured Beam RPC timeouts")
[email protected](autouse=True)
[email protected](scope="class", autouse=True)
def ensure_clean_state():
"""
- Ensure clean state before each test
+ Ensure clean state before each test class
to prevent cross-test contamination.
+ Runs once per test class instead of per test to reduce overhead.
"""
- import gc
- import threading
- import time
-
# Force garbage collection to clean up any lingering resources
gc.collect()
# Log active thread count for debugging
thread_count = threading.active_count()
- if thread_count > 50: # Increased threshold since we see 104 threads
- print(f"Warning: {thread_count} active threads detected before test")
-
+ if thread_count > 50:
+ print(f"Warning: {thread_count} active threads detected before test class")
# Force a brief pause to let threads settle
time.sleep(0.5)
gc.collect()
yield
- # Enhanced cleanup after test
+ # Enhanced cleanup after test class
try:
# Force more aggressive cleanup
gc.collect()
-
# Brief pause to let any async operations complete
time.sleep(0.1)
-
# Additional garbage collection
gc.collect()
except Exception as e:
print(f"Warning: Cleanup error: {e}")
[email protected](autouse=True)
[email protected](scope="class", autouse=True)
def enhance_mock_stability():
- """Enhance mock stability in DinD environment."""
- import time
-
- # Brief pause before test to ensure clean mock state
+ """
+ Enhance mock stability in DinD environment.
+ Runs once per test class instead of per test to reduce overhead.
+ """
+ # Brief pause before test class to ensure clean mock state
time.sleep(0.05)
yield
- # Brief pause after test to let mocks clean up
+ # Brief pause after test class to let mocks clean up
time.sleep(0.05)