Pytest Design Patterns
2024-07-12 –, North Hall

Proper testing of your Python application doesn't require a rewrite into hexagonal architecture (whatever it means 🤷). In this session, we'll explore battle-tested techniques to enhance the maintainability of your test suite.

  • Embracing Well-Known Patterns: The test client or transaction-bound tests are well-established patterns originating from Django. We will explore how to extend these foundational practices within pytest.
  • Employing Fixture Factories: How to ensure that our test data clearly cover the intended scenarios? Unpack the utility of fixture factories, streamlining the setup process.
  • Mocking without Monkey Patching: Learn effective mocking, steering clear of the problematic practice of monkey patching. We'll explore strategies to achieve accurate testing using favorite frameworks and libraries.
  • Covering More with Parametrized Fixtures: Many developers are familiar with pytest fixtures and parametrized tests, but may not be aware of the power of their combination: parametrized fixtures. Discover how to easily build more comprehensive tests.
  • Rethinking Test Categorization: The traditional division into unit and integration tests often falls short in practical application. We'll check an alternative approach that can better align with real-world scenarios.

The goal is not merely to report higher coverage but to have tests that can be trusted. By incorporating established patterns, you'll be empowered to focus on what truly matters.


Expected audience expertise:

Intermediate

See also: Pytest Design Patterns - slides

Miloslav is an experienced software engineer with focus on data processing and web applications.

He is using Python since the version 2.4. EuroPython 2024 will be his third one in the speaker role.