Skip to main content This is the website for an older EuroPython. Looking for the latest EuroPython? Click here!
EuroPython logo

Streamlining Testing in a Large Python Codebase

Track:
DevOps and Infrastructure (Cloud & Hardware)
Type:
Talk
Level:
intermediate
Room:
Terrace 2B
Start:
14:00 on 12 July 2024
Duration:
30 minutes

Abstract

Maintaining code quality through effective testing becomes increasingly challenging as codebases expand and developer teams grow. In our rapidly expanding codebase, we encountered common obstacles such as increasing test suite execution time, slow test coverage reporting and delayed test startup. By leveraging innovative strategies using open-source tools, we achieved remarkable enhancements in testing efficiency and code quality. Challenges Faced:

  • Test Suite Execution Time: The duration of test suite execution escalated significantly as we added more tests over time, hampering development speed.
  • Slow Test Startup: Complex test setup led to prolonged test startup times, impeding developer productivity.
  • Test Coverage Reporting Overhead: Coverage tools introduced substantial overhead and impacted test performance.

Solutions Implemented:

  • Parallel Test Execution: We applied pytest-xdist to distribute tests across multiple runners, significantly reducing test suite execution time and enabling faster development iterations.
  • Optimized Test Startup: Pre-installing dependencies in a Docker image and utilizing Kubernetes for auto-scaling continuous integration runners helped expedite test startup times, improving developer efficiency. For local development, we used pytest-hot-reloading to reload tests fast after code editing.
  • Efficient Test Coverage Reporting: Customizing the coverage tool to collect data only on updated files of pull requests minimized overhead on test coverage reporting. As a result, in the past year, our test case volume increased by 8000, test coverage was elevated to 85%, and Continuous Integration (CI) test duration was maintained under 15 minute

Recording

Play

Resources