Why tests?Plenty of people write code. Some of them make it work and profitable. But sometimes, even the smartest of the best programmers makes a mistake that can cost millions of dollars. How to decrease the possibility of getting into such a fiasco? How do you ensure that you create a program that does exactly what you want? The very simple answer is: write tests!
Python testing basicsDuring this journey, you will learn the very basics of creating tests in Python. You will meet four types of software testing methods. You will create your own tests to check if the program or a data pipeline works as expected before it goes to production. Whether it is the unexpected null, a typo in your dataset, or mixed-up signs in the equation. You can, and you will catch those cases with the tests.
Testing with pytest and unittestAfter the course completion, you will know the types of testing methods, and you will be able to choose the most suitable ones for a specific context. You also will be able to design those tests and implement them in Python using the `pytest` and the `unittest` libraries.
Creating Tests with pytestFree
Learn what a test is and how to run the first one of your own with the pytest library! You will get used to the pytest testing framework and the command-line interface. You will also learn how to process specific contexts, like "failed tests" and "skipping the test" with pytest markers.
Learn what a fixture is and how to simplify your code by using it in tests. You will get familiar with the fixture @pytest.fixture decorator and the fixture tools. You will analyze your code to see the "fixture part" in it. Finally, learn how to use teardowns to prevent software failures.Introduction to fixtures50 xpGetting familiar with fixtures100 xpData preparation100 xpRun with a fixture100 xpChain Fixtures Requests50 xpChain this out100 xpList with a custom length100 xpFixtures autouse50 xpautouse statements50 xpAuto add numbers100 xpFixtures Teardowns50 xpData with teardown100 xpRead data with teardown100 xp
Basic Testing Types
Learn what the basic testing types are and their features. Learn about test cases and how they help to implement tests. You will get more skilled with creating test functions and running pytest from CLI in IDE exercises. Finally, you will be able to differentiate the different testing types and create tests for each of them.Unit testing with pytest50 xpUnit testing terms100 xpCover more test cases50 xpFactorial of number100 xpRun factorial100 xpFeature testing with pytest50 xpFeature or unit testing100 xpAggregate with sum100 xpIntegration testing with pytest50 xpIntegration test or not100 xpRead the file100 xpPerformance testing with pytest50 xpWhat is performance testing?50 xpFinding an element100 xpWhen to use performance testing?50 xpSpeed of loops100 xp
Writing tests with unittest
In this final chapter, you will meet the unittest framework. First, you will learn basic assertion methods, then its CLI interface, and how to use fixtures. Finally, you will put everything together in the practical examples of data pipelines.Meeting the Unittest50 xpFactorial with unittest100 xpIs prime or not100 xpCLI Interface50 xpRun factorial with unittest100 xpErroneouos factorial100 xpUnittest options100 xpFixtures in unittest50 xpTest the string variable100 xpPalindrome check100 xpPractical examples50 xpIntegration and unit tests100 xpFeature and performance tests100 xpEnergy pipeline100 xpCongratulations!50 xp
Alexander LevinSee More
Senior Data Scientist
Alexander is a data scientist with broad experience in helping businesses to benefit from AI, using Machine Learning, Reinforcement Learning, and Python. He obtained an MSc in Applied Mathematics and Informatics from the Higher School of Economics. Alexander loves to share his knowledge and experience, and he is excited to launch courses on DataCamp.