Pytest
The pytest module has the most straightforward approach to unit testing.
- If a filename starts with
test_then the file contains tests. - If a function in such a file has a name starting with
test_then the function is a test. Each test function should contain one or more assertions. Pytest runs the tests and indicates any that fail such as the one below.
# contents of test_sample.py def inc(x): return x + 1 def test_answer(): assert inc(3) == 5