DEV Community

Dzmitry Ananyeu
Dzmitry Ananyeu

Posted on

๐ŸŽฏ ๐‹๐ž๐ญโ€™๐ฌ ๐ญ๐š๐ฅ๐ค ๐š๐›๐จ๐ฎ๐ญ ๐…๐ฅ๐š๐ค๐ฒ ๐“๐ž๐ฌ๐ญ๐ฌ โ€“ ๐ญ๐ก๐ž ๐ฌ๐ข๐ฅ๐ž๐ง๐ญ ๐ฉ๐ซ๐จ๐๐ฎ๐œ๐ญ๐ข๐ฏ๐ข๐ญ๐ฒ ๐ค๐ข๐ฅ๐ฅ๐ž๐ซ ๐ข๐ง ๐ญ๐ž๐ฌ๐ญ ๐š๐ฎ๐ญ๐จ๐ฆ๐š๐ญ๐ข๐จ๐ง.

You know the ones:
๐Ÿ” They pass.
โŒ Then they fail.
โœ… Then magically pass again.
All without a code change.

๐Ÿคฏ Why are they so dangerous?

  • They break trust in your test suite
  • Waste hours of debugging
  • Block CI/CD pipelines
  • Lead to โ€œIgnore this test, it always fails ๐Ÿ˜’โ€

๐Ÿ›  Real-world causes Iโ€™ve seen:

  1. Timing issues Example: wait_for_element() didnโ€™t wait long enough in slow environments
  2. Data dependency A test passes locally but fails in CI because shared data is already modified
  3. 3rd-party services API mock wasnโ€™t stable, external service had rate-limiting
  4. Environment drift Works on Chrome vX, fails on vX+1
  5. Bad Locator Find several web elements (not unique)
  6. Fails only when run in parallel

โœ… How to fight flakiness:
๐Ÿ”น Use explicit waits, not hard sleeps
๐Ÿ”น Reset or isolate test data
๐Ÿ”น Add retries ONLY where absolutely needed (@flaky, rerunfailures) - here need to be very carefully
๐Ÿ”น Log and analyze fail patterns over time
๐Ÿ”น Isolate flaky tests and flag them for review
๐Ÿ”น Use mocks to simulate unstable services
๐Ÿ”น Run tests in consistent, clean environments (Docker, CI agents)

๐Ÿ’ฌ A flaky test is worse than no test at all - because it lies to you.

qa #flakytests #automation #pytest #testautomation #softwaretesting #cicd #devops #linkedintech #qaengineer

Image description

Top comments (0)