# pytest

> The best-known test tool for Python. It finds and runs your tests.

**Field:** Software Development  
**Category:** Testing & Quality  
**Also known as:** Pytest, py.test

## Think of it like

Think of it like a helper. They find every quiz in the house and mark them all.

## Definition

pytest is the most popular tool for testing Python code. A test is a plain function whose name starts with test_, inside a file named test_ something. You check results with Python's own assert, and pytest shows the values when one fails. Fixtures let tests share set-up, like a fresh database. Hundreds of plugins add things like coverage reports.

## Example

Lucy writes test_total in test_cart.py. She types pytest, and it finds the test, runs it and prints 1 passed.

## Example code

```console
$ pytest -v test_cart.py
test_cart.py::test_total PASSED     [100%]
1 passed in 0.02s
```

pytest names each test it ran and whether it passed.

## Why it matters

Tests are short to write, and failures show exactly which values did not match.

## Common mistake

Naming a test check_total instead of test_total. pytest skips it, so it never runs and never fails.

## Three principles

- **Plain functions.** Named test_ something.
- **Plain assert.** Shows values on failure.
- **Fixtures.** Shared set-up.

## Related terms

- [Test Runner](https://learn.benibix.com/term/development/test-runner)
- [Python](https://learn.benibix.com/term/development/python)
- [Assertion](https://learn.benibix.com/term/development/assertion)
- [Test Coverage](https://learn.benibix.com/term/development/test-coverage)
- [Test Fixture](https://learn.benibix.com/term/development/test-fixture)

---

Source: https://learn.benibix.com/term/development/pytest
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
