Pytest can do a lot more than you'd think

Tushar Sadhwani (~tushar29)




Pytest is the de-facto testing framework for Python. And it's for good reason, pytest can scale from the smallest project with a couple unit tests, to the largest Python projects ever created. Pytest's extensive flexibility paired with the huge ecosystem of pytest plugins makes it suitable for pretty much any testing usecase you could think of.

"But what can pytest do, other than collecting and running test functions?"

I'm glad you asked.


This will be a bit more of a "Shotgun buffet" style of a talk, where I'll throw a bunch of useful tidbits about Pytest, and you can pick up the ones most relevant to you.

Some things we will learn about:

  • The lifecycle of a Pytest test run
  • Hooking into pytest events to extend its functionality
  • Running setup and teardown code per-test, per-file etc.
  • Pytest markers, and what are they used for
  • Using parametrization to generate tests from data
  • Using pytest_generate_tests to generate tests at runtime
  • Collecting stats about tests that ran and tests that didn't
  • Using the lifecycle hooks to customize your test environment
  • Some must-use pytest plugins (such as slow, random-order, cov and xdist)


The talk itself won't require any in-depth knowledge about python or pytest, but having used pytest once or twice before would be great for following the talk contents.

Speaker Info:

Long-term Python developer, author, OSS contributor and speaker, Tushar currently works as a Software Engineer building language tools at DeepSource.

When not working, he tries to contribute to the Python developer tools ecosystem, like black, ruff, flake8 and mypy.

Speaker Links:

Section: Core Python
Type: Talk
Target Audience: Intermediate
Last Updated: