pytest runs Python tests and reports which checks pass or fail. Use it repeatedly while developing and refactoring programs. section 1.3 section 1.12
Useful command patterns include:
- Run a test file with verbose output: pytest -v test.py. section 1.3
- Stop after the first failure and show details: pytest -xv test.py. section 1.3
- Use make test as a shortcut when a Makefile delegates to pytest. section 1.12
Reading a test run
A successful run can collect five tests and report each as PASSED, ending with “5 passed.” With -xv, pytest stops at the first failing test and displays the assertion and error details. section 1.12 section 1.3
$ pytest -v test.py ============================= test session starts ============================== ... collected 5 items test.py::test_exists PASSED [ 20%] #1 test.py::test_runnable PASSED [ 40%] #2 test.py::test_executable FAILED [ 60%] #3 test.py::test_usage FAILED [ 80%] #4 test.py::test_input FAILED [100%] #5 =================================== FAILURES ===================================
Inspect a verbose pytest run showing collected tests, failures, assertions, and command output. section 1.3










