Testing with pytest
Part of the Python course
Welcome back. Up to now you have run code and checked the output with your eyes. That works for a few lines, but the moment you change anything, you have to re-check everything. Tests do that re-checking for you, every time, in seconds. They catch the small breakages you would have missed, and they let you change code with confidence because you can prove out loud that the old behavior still works.
This lesson uses two files: calculator.py (the code under test) and test_calculator.py (the tests). Your workspace already has test_calculator.py. There is no calculator.py in your lesson folder yet. Create it with this code: press Play on the block and the file is made for you. Pressing Play again does not make a second copy. ...
Want to learn Python Testing with pytest in a real environment?
Click below, get a fresh Linux box with Python ready to go, and work through Testing with pytest hands-on with an AI tutor that knows your code.
Start this lessonTesting with pytestWhat you'll learn
- Test functions
- Assert
- Running pytest
- Parametrize
- Fixtures
Read this lesson in your language
All lessons in this course
19 lessons- 1Hello, Python20 min
- 2Numbers and Strings25 min
- 3Asking the User a Question15 min
- 4Control Flow30 min
- 5Lists and Tuples30 min
- 6Dictionaries and Sets30 min
- 7Functions30 min
- 8Comprehensions25 min
- 9Files and IO30 min
- 10Modules and Packages30 min
- 11Classes and OOP35 min
- 12Inheritance and Composition30 min
- 13Exception Handling30 min
- 14Iterators and Generators30 min
- 15Decorators30 min
- 16Context Managers25 min
- 17Concurrency: Threads and Async40 min
- 18Testing with pytest35 min
- 19Packaging and Deployment35 min
