TOPIC 08/2216 MINNOT STARTED

pytest from zero: your first tests, fixtures and markers

Write a first test in plain Python, read a failing assertion, share setup with a fixture, run one input set after another, and label tests with markers so you can…

L1–L4 are part of the Pro pass

L0 Explain simply

Analogy: a driving test with a checklist. Each move gets a tick or a cross. The car is set the same way before each move. One move is tried in the rain and at night. A few moves are marked quick.

Tom organizes checks for synthetic Daily List with pytest. A plain test function contains an expected-result check. A setup fixture supplies a resource or state through a named dependency. Markers and inputs have different roles: a marker describes/selects tests, while parametrization supplies cases for repeated invocations.

The driving- helps distinguish an from preparing the car. It does not make a test independent automatically.

The picture has a limit. Discovery can be configured, test cases need meaningful expected results, and registering a marker does not make an assertion correct. Use the selected project's actual configuration rather than an assumed universal naming rule.

(SYNTHETIC / TRAINING ONLY: Daily List and every named person are invented.)

PLAIN WORDS · 2 in this section
pytest
A free Python tool that finds and runs checks.
configured
set up with chosen settings

PICTURE IT

The picture is the one the lesson above opens with. The table below shows how each part of it matches the software.

THE REAL JOB Collect pytest cases with explicit inputs, fixtures, markers and expected-result checks.

  1. Test
  2. Set up
  3. Repeat
Driving test

HOW THE PICTURE MAPS

How each part of the picture matches the software
In the pictureIn the software
A driving move with a tick or crossA test
Setting the car up the same wayA fixture
Trying a driving move in rain and at nightParametrize
A quick-test labelA marker

WHERE THIS PICTURE STOPS

  • Discovery rules can be configured; a naming convention is not a complete account of every pytest collection path.
  • Markers, fixtures and parametrization have distinct jobs and do not automatically validate the business oracle.

HOOK

Checklist, set-up, repeats.

TELL A FRIEND

A driving test: checklist, set-up, repeats.

OFTEN MIXED UP WITH Your first scripted API check: from a manual request to a repeatable test. That topic scripts a first check. This one teaches the pytest tool that runs checks like it.

Sources & standards — 4 sources
  1. Implementation-specific

    pytest good integration practices ↗ — pytest-dev contributors · Default file/function discovery; configurable and unittest collection boundaries (selected actual primary passages read 7 November 2026; live publisher documentation, not every linked section or historical release).

    Default file/function discovery; configurable and unittest collection boundaries. Product/configuration-specific guidance; not a universal team practice. · Checked 2026-11-07

    Selected actual primary passages read, including the specific fixture/marker/collection boundaries described. Daily List rules, people and paths are synthetic; no pytest/xdist execution or complete production fixture design is claimed. Live documentation has no fixed edition claimed.

  2. Implementation-specific

    pytest markers guide ↗ — pytest-dev contributors · Custom marker registration; unknown-mark warnings and strict-marker errors (selected actual primary passages read 7 November 2026; live publisher documentation, not every linked section or historical release).

    Custom marker registration; unknown-mark warnings and strict-marker errors. Product/configuration-specific guidance; not a universal team practice. · Checked 2026-11-07

    Selected actual primary passages read, including the specific fixture/marker/collection boundaries described. Daily List rules, people and paths are synthetic; no pytest/xdist execution or complete production fixture design is claimed. Live documentation has no fixed edition claimed.

  3. Implementation-specific

    pytest fixture guide ↗ — pytest-dev contributors · Scopes and parameter caching; yield-setup failure; broader/narrower dependency lifetimes (selected actual primary passages read 7 November 2026; live publisher documentation, not every linked section or historical release).

    Scopes and parameter caching; yield-setup failure; broader/narrower dependency lifetimes. Product/configuration-specific guidance; not a universal team practice. · Checked 2026-11-07

    Selected actual primary passages read, including the specific fixture/marker/collection boundaries described. Daily List rules, people and paths are synthetic; no pytest/xdist execution or complete production fixture design is claimed. Live documentation has no fixed edition claimed.

  4. Implementation-specific

    pytest test-function parametrization ↗ — pytest-dev contributors · Parametrization levels; decorator with input/expected pairs and separate invocations (selected actual primary passages read 7 November 2026; live publisher documentation, not every linked section or historical release).

    Parametrization levels; decorator with input/expected pairs and separate invocations. Product/configuration-specific guidance; not a universal team practice. · Checked 2026-11-07

    Selected actual primary passages read, including the specific fixture/marker/collection boundaries described. Daily List rules, people and paths are synthetic; no pytest/xdist execution or complete production fixture design is claimed. Live documentation has no fixed edition claimed.

PRACTISE AND KEEP

Sources for this topic — 4 sources
  1. Implementation-specific

    pytest good integration practices ↗ — pytest-dev contributors · Default file/function discovery; configurable and unittest collection boundaries (selected actual primary passages read 7 November 2026; live publisher documentation, not every linked section or historical release).

    Default file/function discovery; configurable and unittest collection boundaries. Product/configuration-specific guidance; not a universal team practice. · Checked 2026-11-07

    Selected actual primary passages read, including the specific fixture/marker/collection boundaries described. Daily List rules, people and paths are synthetic; no pytest/xdist execution or complete production fixture design is claimed. Live documentation has no fixed edition claimed.

  2. Implementation-specific

    pytest markers guide ↗ — pytest-dev contributors · Custom marker registration; unknown-mark warnings and strict-marker errors (selected actual primary passages read 7 November 2026; live publisher documentation, not every linked section or historical release).

    Custom marker registration; unknown-mark warnings and strict-marker errors. Product/configuration-specific guidance; not a universal team practice. · Checked 2026-11-07

    Selected actual primary passages read, including the specific fixture/marker/collection boundaries described. Daily List rules, people and paths are synthetic; no pytest/xdist execution or complete production fixture design is claimed. Live documentation has no fixed edition claimed.

  3. Implementation-specific

    pytest fixture guide ↗ — pytest-dev contributors · Scopes and parameter caching; yield-setup failure; broader/narrower dependency lifetimes (selected actual primary passages read 7 November 2026; live publisher documentation, not every linked section or historical release).

    Scopes and parameter caching; yield-setup failure; broader/narrower dependency lifetimes. Product/configuration-specific guidance; not a universal team practice. · Checked 2026-11-07

    Selected actual primary passages read, including the specific fixture/marker/collection boundaries described. Daily List rules, people and paths are synthetic; no pytest/xdist execution or complete production fixture design is claimed. Live documentation has no fixed edition claimed.

  4. Implementation-specific

    pytest test-function parametrization ↗ — pytest-dev contributors · Parametrization levels; decorator with input/expected pairs and separate invocations (selected actual primary passages read 7 November 2026; live publisher documentation, not every linked section or historical release).

    Parametrization levels; decorator with input/expected pairs and separate invocations. Product/configuration-specific guidance; not a universal team practice. · Checked 2026-11-07

    Selected actual primary passages read, including the specific fixture/marker/collection boundaries described. Daily List rules, people and paths are synthetic; no pytest/xdist execution or complete production fixture design is claimed. Live documentation has no fixed edition claimed.

Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.