Writing clean tests with pytest

The pytest framework allows for cleaner tests to be written but also for efficient running of tests with multiple plugins.


Coverage: pytest-cov

The pytest-cov plugin allows you to run coverage checks with pytest.

Flake8: pytest-flake8

The pytest-flake8 plugin allows you to run flake8 checks with pytest.

Stochastic effects: pytest-randomly

The pytest-randomly plugin does two things (for Nashpy):

  1. It randomly shuffles the order of tests: this ensures that tests passing is not dependent on the order in which they run.

  2. It seeds stochastic tests to ensure that any exceptions are reproducible. In practice this has little effect here as ideally stochastic tests are seeded or written with hypothesis.

Nicer look: pytest-sugar

The pytest-sugar plugin changes the look of pytest.

Further plugins

The Talk Python to Me podcast episode 267 featured a discussion of a number of pytest plugins: https://talkpython.fm/episodes/show/267/15-amazing-pytest-plugins