Python for Software Engineers
Back to Production Python

Testing with pytest

The dominant Python testing framework. Fixtures, parametrization, mocking, coverage. FIND_VIDEO: search 'python pytest tutorial fixtures parametrize' — recommended channel: ArjanCodes / mCoding. Aim for 11 min or under.

23 minutesVideo LessonPDF notes
🎯 Free Guest Mode: You are learning for free. Sign in to save your completion progress and quiz answers.
Loading progress...

Key moments

  1. Parameterization Rationale — The instructor explains the motivation for data-driven testing and avoiding test duplication.
  2. Pytest Parameterization Mechanisms — An overview introduces the three mechanisms: fixtures, test markers, and custom hooks.
  3. Fixture Parameterization — The lesson demonstrates defining parameterized fixtures using params and accessing values via request.param.
  4. Function Parameterization — The tutorial shows how to decorate test functions with pytest.mark.parametrize for data-driven assertions.
  5. Advanced Dynamic Parameterization — The instructor summarizes the lesson and introduces the pytest_generate_tests hook for CLI and browser matrices.
PDF notes

Frequently asked questions

Why does a parameterized fixture require the request argument?

Pytest uses the built-in request fixture to track test lifecycle and context. The active iteration's parameter value is exposed exclusively through request.param.

Can I use multiple @pytest.mark.parametrize decorators on a single test?

Yes. Pytest will generate a Cartesian product of all parameter combinations across the stacked decorators.

When should I use fixture parameterization instead of test parameterization?

Use fixture parameterization when multiple tests share the same multi-state setup or teardown logic, such as testing against multiple database configurations.

How was this lesson?

Your feedback helps us refine explanations and catch bugs.