pytest - simple, rapid and fun testing with Python

Florian Bruhin

Thursday 16:15 in Ferrum

Preparation and Repository

See The-Compiler/pytest-basics on GitHub for exercise code and preparation steps. Please make sure you have at least a virtualenv with pytest (or the full requirements.txt in the repo) set up and the code cloned before the training starts, so that we don't lose any time with the boring setup parts.

See the README for detailed setup instructions.

Schedule

  • (25 minutes) pytest feature walkthrough:

    • Automatic test discovery
    • Assertions without boilerplate via the assert statement
    • Configuration and commandline options
    • Marking and skipping tests
    • Data-driven tests via parametrization
    • Exercises
  • (60 minutes) pytest fixture mechanism:

    • Setup and teardown via dependency injection
    • Declaring and using function/module/session scoped fixtures
    • Using fixtures from fixture functions
    • Parametrizing fixtures
    • Looking at useful built-in fixtures (managing temporary files, patching, output capturing)
    • Exercises
  • (5 minutes) Where to go next:

    • Useful CLI arguments to deal with failing tests
    • Overview of the plugin ecosystem around pytest

Florian Bruhin