Python Bootcamp for Data week 3: Testing in Python with Pytest
This week, you will learn the basics of Python testing. From a brief overview of the standard library to using a more modern approach with Pytest, one of the most popular testing libraries in Python. By the end of this week, you should be comfortable working with existing tests, creating new tests, and debugging test failures.
🎥 Click the image below to access week 3 of the full course on O'Reilly
This is week 3 (out of 4) of the Python Bootcamp for Data. The whole course has four weeks:
- Week 1: Introduction to Python
- Week 2: Python Functions and Classes
- Week 3: Testing In Python
- Week 4: Introduction to Pandas and Numpy
In this week you will learn to:
- Understand the basics of testing and its importance
- Write and run tests with functions and classes
- Use Pytest for running and creating tests
If you are wondering about why test at all, first you should know about some common excuses:
It takes too much time
It isn't that it takes too much time, but it does take time. What takes more time than testing is debugging what went wrong and ensuring nothing broke with the latest change.
It is too difficult
Like almost anything, it takes practice to make progress. Take the time to understand what makes a good test, and why slow tests aren't that good. It is better to know that a window in your house is broken than a test that tells you that your house has some undefined problem somehwere.
We don't have bugs
Eventually, all software has bugs. And it is better to fix a bug once, not twice. A test will help you understand what and how it broke, and give you confidence on the fix.
If it doesn't work, who do we blame? The customer?
If you are releasing software, do you wait until a user finds a problem? The idea of testing is primarily to increase confidence.
Software tends to grow, dependencies change, and almost all engineers will forget about some crucial part of their software at some point. If you are making sure that a change is doing what is supposed to be doing, imagine having 30 steps to verify it all works.
You will miss a step if you need 30 steps to verify everything works.