Testing with pytest
18-minute lesson · module-testing-04
You are previewing this course as a guest
Read anything and run any exercise you like. It all runs in your own browser, so nothing here is saved: no XP, no progress, and the AI tutor needs an account. Sign in and your work starts counting.
Testing with pytest
18-minute lesson · module-testing-04
- Write a test as a plain test_ function that uses a bare assert.
- Run a test suite from the terminal with the pytest command.
- Read pytest's output to see which tests passed and why one failed.
- Use a simple fixture to provide reusable setup to tests.
Source attribution
Status: adapted
How to Think Like a Computer Scientist: Interactive Edition — source · Unit Testing / Testing With pytest
Adaptation notes. Read-along lesson. pytest is a command-line test runner that discovers and runs test files from a terminal; that workflow does not exist in the Pyodide sandbox, so there is no graded coding step. Code is for reading and local running. Contrasts with the prior unittest lesson. Examples are ours.
License notes. Original chapter is GNU FDL 1.3 (Brad Miller, David Ranum, and the upstream Elkner/Downey/Meyers text). No verbatim text reproduced. pytest is MIT-licensed; only API names and CLI usage are referenced.