| 1 | test function | calls your code once and asserts on the result | a test file under tests/ | whatever its asserts compare | a green run for a behaviour nobody asserted on |
|---|
| 2 | assert rewriting | makes a failing assert print the values on both sides | test files and conftest.py, at import | nothing; it only adds detail to failures | a bare AssertionError with no values, from a helper module |
|---|
| 3 | reporter | prints each result, the failure sections and the summary | the pytest process | nothing; it reports what the runner found | a failed CI job: any exit code other than zero |
|---|
| 4 | config and rootdir | fix the project root and the options for every run | the first config file found walking upward | option names and value types, when strict | options silently ignored: pytest read a different config file |
|---|
| 5 | collector | walks the test paths and picks tests by name | the rootdir and testpaths | file, class and function names | a new test that never runs: its name doesn’t match |
|---|
| 6 | test items | list every test to run, each with a node ID | the collector’s output | nothing; they are the list | “collected 0 items”, or fewer items than you wrote |
|---|
| 7 | runner | runs each test in three phases: setup, call, teardown | every test item | nothing; it runs the phases in order | ERROR for a broken fixture, FAILED for a broken test |
|---|
| 8 | fixtures | build what a test needs and clean it up afterwards | a test’s parameter names | nothing; they prepare and tidy | “fixture not found”, or state left behind by missing cleanup |
|---|
| 9 | conftest.py | shares fixtures with every test below its directory | a directory under tests/ | nothing; it only holds fixtures | a fixture missing in one folder: its conftest is elsewhere |
|---|
| 10 | fixture scope | sets how often a fixture runs and how long it lives | each fixture | that a wide fixture uses no narrower one | tests that pass alone and fail together: shared state |
|---|
| 11 | tmp_path | gives each test its own empty directory | any test or fixture that names it | nothing; it only creates the directory | tests colliding on files written somewhere else |
|---|
| 12 | parametrize | turns one test function into one test per case | a test function, during collection | nothing; it multiplies the test | one failing case hiding the rest: a loop was used |
|---|
| 13 | markers | label tests so a run can select or skip them | tests, classes or single cases | that names are registered, when strict | a misspelled marker’s test running when it should not |
|---|
| 14 | the seam | lets the caller choose each dependency | the parameters of your function | nothing; it is a place to pass things in | a test that needs the network: nothing could be passed in |
|---|
| 15 | fakes | stand in for a dependency with a small working version | passed in through the seam | nothing; they behave as the real thing should | green tests and a production failure: the fake drifted |
|---|
| 16 | Mock | accepts any call, records it and returns scripted answers | passed in, or placed by patch | call arguments, and signatures when autospecced | a test that passes with a wrong call: no spec was given |
|---|
| 17 | patch and monkeypatch | point a name at a stand-in for one test | module attributes, environment variables, dict items | that the patched name exists | a mock never called, while the real function ran |
|---|
| 18 | the adapter | holds everything your code knows about the vendor’s API | between your code and the payment API | the vendor’s status codes and field names | a paid customer marked overdue: a response was misread |
|---|
| 19 | integration and contract tests | run the adapter and the fake against the same checks | the one line that leaves the process | that the fake and the real API agree | a failing contract test, before production finds the difference |
|---|
| 20 | coverage | records which lines and branches the tests ran | a plugin inside pytest | nothing about quality; only what was executed | missing line numbers for code no test reaches |
|---|
| 21 | random order | shuffles tests each run and prints the seed | a plugin, during collection | nothing; it exposes order dependence | a failure that appears with one seed and not another |
|---|
| 22 | parallel workers | split the tests across several processes | a plugin; each worker is a process | nothing; they only divide the work | failures only under -n: tests sharing files or ports |
|---|
| 23 | CI runner | runs the whole suite on every push | outside your machine, from a clean checkout | the exit code of the run | a red build for a change that passed on your laptop |
|---|
| · | code under test | does the work the tests exist for | imported by the tests | your business rules | a failing assert naming the wrong value |
|---|
| · | real dependencies | are what the code calls in production | outside the test process | nothing in a test run | real emails or charges sent by a test |
|---|
| · | mocker | offers patch as a fixture, undone automatically | tests that name it (pytest-mock) | the same as patch | the same symptoms as a patch on the wrong name |
|---|