Test Python code with pytest fixtures and parametrization

8 steps · about 2 h 30 min · Beginner

  1. Run pytest and select tests (article, pytest docs, 15 min)

    Teaches the command-line options you will use every day.

  2. Skip tests and mark expected failures (article, pytest docs, 15 min)

    Shows how to handle tests that cannot run everywhere.

  3. Learn fixtures from the reference (article, pytest docs, 30 min)

    Explains fixture scope, autouse and teardown precisely.

  4. Run one test over many inputs (article, pytest docs, 20 min)

    Replaces copy-pasted tests with a data table.

  5. Use temporary files and directories (article, pytest docs, 10 min)

    Lets file-handling tests run safely and cleanly.

  6. Inspect log output in tests (article, pytest docs, 15 min)

    Lets you assert on logging without printing.

  7. Organise tests with marks (article, pytest docs, 15 min)

    Lets you skip, expect failures and select slow tests.

  8. Practise with an end-to-end pytest tutorial (article, Real Python, 30 min)

    Ties the pieces together in a worked example.