🧪pytest
Also known as Pytest, py.test
The best-known test tool for Python. It finds and runs your tests.
Think of it like
Think of it like a helper. They find every quiz in the house and mark them all.
Example
Lucy writes test_total in test_cart.py. She types pytest, and it finds the test, runs it and prints 1 passed.
Why it matters
Tests are short to write, and failures show exactly which values did not match.
Definition
Example code
console
$ pytest -v test_cart.py
test_cart.py::test_total PASSED [100%]
1 passed in 0.02sCommon mistake
Key takeaways
- 1Plain functions. Named test_ something.
- 2Plain assert. Shows values on failure.
- 3Fixtures. Shared set-up.