Python 5.6The video for this lesson is on its way.
Everything else is ready: study the parts, the key terms and the quiz below.
Python 5.6Code walkthrough8 parts
Testing with assert and pytest
Check that code does what it should, automatically and every time it changes.
Loading your progress…Next: 5.7 Formatting, Linting and Type Checking
In this lesson8 parts
- 01The bug that could come back
- 02assert
- 03A test file
- 04What to test
- 05Reading a failure
- 06Tests while you change code
- 07Where tests mislead
- 08Recap, your challenge, and next
Key terms
The words this lesson introduces, each in one line. The module’s glossary collects them all.
- assertion
- A statement that a condition is
True;assertraisesAssertionErrorwhen it is not. - edge case
- An input at the limit of what the code handles: an empty list, one item, an empty string.
- error case
- An input the code should refuse, checked by testing that it raises.
- pytest
- A tool that finds the test functions in a project and runs them all.
- regression test
- A test written from a bug, so that the bug can not come back unnoticed.
- test
- A function that runs code and asserts what it should give.
Quiz 5 questions
Your first pick on each question is the one that counts, and a right one earns a coin. Getting one wrong here is how the lesson sticks.
Practice
Problems to solve in your own notebook. Each states the problem, not the steps: working out the steps is the exercise. Level A applies the lesson, B combines it with earlier ones, C stretches it.
Common mistakes
What you will see when it goes wrong, why it happens, and the fix.
Where it’s used
Where this lesson’s ideas turn up in real work.