Playwright + Python · Lesson 35 of 37

0/37 done

Module 35: Retries & Flaky Tests

35. Diagnosing & Eliminating Test Flakiness in Python

16 minlesson

Your task

Implement is_retryable_error_message(err_msg: str) -> bool:

  1. Return "timeout" in err_msg.lower() or "closed" in err_msg.lower().

Write it in the editor, then press Check answer (Ctrl + Enter).

Flaky Test Mitigation

  1. Automated Retries via CLI:
bash
# Re-run failed tests up to 2 times:
pytest --reruns 2 --reruns-delay 1
  1. 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.

Key Takeaways & Walkthrough Summary

Flaky tests erode team confidence. In this lesson, we examine the root causes of test flakiness: shared test data, order dependency, and timing issues. You will configure automated retries with pytest-rerunfailures and diagnose root causes. Let's make tests rock-solid!

Part of the Playwright + Python course (Playwright with Python). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.

Common Doubts & Lesson Q&A

Is relying on test retries a good long-term solution?

No. Retries are a safety net for transient network blips on CI. The underlying flakiness must still be investigated and resolved using Trace Viewer.

Ready? Solve the task in the editor

Use Check answer to mark it complete. Hints are there if you need them.

Python
Skip