Tests in Python
Tests in Python: Your First Tests with pytest, Testing Edge Cases and Errors, Fixtures and Temporary Files.
Updated
- Your First Tests with pytest (Journeyman): A test is a small function that runs your code on an example and makes sure the answer is right, and pytest finds every test, runs it, and shows exactly what came back when one fails.
- Testing Edge Cases and Errors (Journeyman): Bugs hide at the edges of what a function accepts, so good tests try zero and empty values, the smallest and biggest values allowed and each side of a boundary, make sure bad values are refused with pytest.raises, and run many examples through one test with parametrize.
- Fixtures and Temporary Files (Journeyman): A pytest fixture builds the setup several tests share and hands each test a fresh copy, tmp_path gives each test its own empty folder to write files in, and capsys lets a test read what a function printed.