35. Diagnosing & Eliminating Test Flakiness in Python

Flaky Test Mitigation

1. Automated Retries via CLI:
# Re-run failed tests up to 2 times:
pytest --reruns 2 --reruns-delay 1

2. Root Cause Analysis:
- Check if Test B depends on data created by Test A.
- Use page.expect_response() instead of waiting for DOM side effects.
- Use user-facing accessible locators instead of dynamic CSS classes.

Task

  • Implement is_retryable_error_message(err_msg: str) -> bool:
  • 1. Return "timeout" in err_msg.lower() or "closed" in err_msg.lower().
πŸ’‘Common doubts
Did you like the problem?
Lesson 35 of 37
Python
Loading code editor…
Next