Skip to content

Commit ed7a75e

Browse files
committed
Fix flaky e2e test and pytest warning
Use wait_for in BasePage.is_visible() to eliminate race condition causing intermittent test_system_page_layout failures. Replace return True/False with pytest.fail() in test_startup.py to fix PytestReturnNotNoneWarning.
1 parent 4482638 commit ed7a75e

2 files changed

Lines changed: 18 additions & 18 deletions

File tree

tests/tools/e2e/pages/base_page.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,21 +292,21 @@ def take_screenshot(self, name: str, full_page: bool = True) -> bytes:
292292
"""
293293
return self.page.screenshot(full_page=full_page)
294294

295-
def is_visible(self, text: str) -> bool:
296-
"""Check if text is visible on page.
295+
def is_visible(self, text: str, timeout: int = 10000) -> bool:
296+
"""Check if text is visible on page, waiting for it to appear.
297297
298298
Args:
299299
text: Text to search for
300+
timeout: Maximum time to wait in milliseconds (default 10s)
300301
301302
Returns:
302-
bool: True if text is visible
303+
bool: True if text is visible within the timeout
303304
"""
304305
try:
305-
# Use first() to avoid strict mode violation with multiple matches
306306
elem = self.page.get_by_text(text).first
307-
return elem.is_visible()
307+
elem.wait_for(state="visible", timeout=timeout)
308+
return True
308309
except (TimeoutError, AttributeError):
309-
# Element not found or not visible
310310
return False
311311

312312
def get_text_value(self, label: str) -> str:

tests/tools/e2e/test_startup.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import sys
55
import time
66

7+
import pytest
78
import requests
89

910

@@ -34,13 +35,10 @@ def test_streamlit_startup():
3435
# Check if process is alive
3536
if process.poll() is not None:
3637
stdout, stderr = process.communicate()
37-
print("❌ Process died!")
38-
print(f"Return code: {process.poll()}")
39-
if stderr:
40-
print(f"Stderr: {stderr}")
41-
if stdout:
42-
print(f"Stdout: {stdout}")
43-
return False
38+
pytest.fail(
39+
f"Process died! Return code: {process.poll()}\n"
40+
f"Stderr: {stderr}\nStdout: {stdout}"
41+
)
4442

4543
# Try health check
4644
try:
@@ -59,17 +57,19 @@ def test_streamlit_startup():
5957
process.terminate()
6058
process.wait(timeout=5)
6159
print("✓ Process terminated cleanly")
62-
return True
60+
return
6361
except requests.exceptions.RequestException as e:
6462
elapsed = time.time() - start_time
6563
print(f" [{elapsed:.1f}s] Health check failed: {e}")
6664
time.sleep(0.5)
6765

68-
print("❌ Timeout: Streamlit app didn't respond within 60 seconds")
6966
process.terminate()
70-
return False
67+
pytest.fail("Timeout: Streamlit app didn't respond within 60 seconds")
7168

7269

7370
if __name__ == "__main__":
74-
success = test_streamlit_startup()
75-
sys.exit(0 if success else 1)
71+
try:
72+
test_streamlit_startup()
73+
sys.exit(0)
74+
except Exception:
75+
sys.exit(1)

0 commit comments

Comments
 (0)