Loading topic
pytest from a terminal inside a virtual environment, and read a basic traceback. You should also know that assert is a Python statement and that tests are functions named test_* in files named test_*.py. The earlier chapters on discove4 min readassert, and know how Python raises and catches exceptions. If a test file runs for you with pytest -v, you have what you need.4 min readassert (covered earlier in this tutorial) and that you know what a float is in Python. It explains why exact float comparison fails, how pytest.approx decides two numbers are close enough, and where it can surprise you.4 min readassert, and read generators (functions that use yield). Fixtures are how pytest shares setup code between tests without copying it.4 min readpytest from a terminal. It covers how long a fixture's value lives, how to share an expensive resource across tests, and how to release resources reliably.4 min read@pytest.fixture and use yield for cleanup. It also assumes you know how pytest discovers test files. Here you will move fixtures out of individual test modules so that many files can use them without importing anything.4 min readassert, and use pytest.raises and pytest.approx. It also assumes you can read the output of pytest -v.4 min readassert, and read a pytest report. It also assumes you have seen pytest.mark.parametrize. Parametrize is itself a marker, so you already use the mechanism described here.5 min readtmp_path, monkeypatch, and capsys. Each one isolates a test from something outside th4 min readassert, use fixtures, and use monkeypatch from the previous chapter. You should also know how Python imports names into modules. The chapter covers how to replace a collaborator with a test double. It also covers how to check the calls m4 min read@pytest.mark.slow). It also assumes you have a project with a pyproject.toml file or can create one. The goal is to move the options you type on every run into a file that every developer and every CI job share5 min readpytest -v and -k, and edit pyproject.toml. The earlier chapters on running pytest and configuration cover these. You also need a virtual environment where you can install packages.5 min readconftest.py. It also assumes you know how to configure pytest in pyproject.toml. Here you will use both to keep a suite manageable as the number of tests grows from dozens to thousands.5 min readassert, use fixtures and parametrize, and run pytest from the terminal. It covers habits that keep a suite useful after hundreds of tests and many months of changes.5 min read