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.

Ready to continue?

Mark this lesson as complete when you're ready to proceed.

Key moments

  1. Introduction and Agenda — Outlines the core topics covering basic pytest usage, grouping, fixtures, and parameterization.
  2. Installation and Overview — Explains pytest benefits and demonstrates installation via pip or PyCharm interpreter settings.
  3. First Test and Assertions — Demonstrates writing a basic test function and evaluating test output with the assert keyword.
  4. Substring and Marker Filtering — Shows how to run targeted subsets of tests using -k substring matching and -m custom markers.
  5. Grouping Tests in Classes — Illustrates structuring multiple test methods together under a single test class.
  6. Pytest Fixtures — Demonstrates creating reusable setup functions using the @pytest.fixture decorator.
  7. Parametrized Tests — Shows how to feed multiple sets of arguments into a single test using @pytest.mark.parametrize.
  8. Skip and Xfail Markers — Explains how to skip tests or mark known failures without breaking the overall test run.
  9. API Testing Demonstration — Applies pytest assertions and fixture setups to send requests and validate external REST API responses.
PDF notes

Frequently asked questions

What is the difference between a skipped test and an xfailed test?

A skipped test is not executed at all, whereas an xfailed test executes but does not register as a failure in test reports if its assertion fails.

Do test classes need to inherit from a base class like unittest.TestCase?

No, pytest test classes do not require inheritance; they only need to follow the naming convention of starting with 'Test'.

What happens when an assertion fails inside a test method?

Pytest halts execution of that specific method immediately, reports the failure details, and moves on to execute the next test.

How was this lesson?

Your feedback helps us refine explanations and catch bugs.