Skip to main content
HomePythonIntroduction to Testing in Python

Introduction to Testing in Python

Master Python testing: Learn methods, create checks, and ensure error-free code with pytest and unittest.

Start Course for Free
4 Hours16 Videos53 Exercises

Create Your Free Account

GoogleLinkedInFacebook

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.
GroupTraining 2 or more people?Try DataCamp For Business

Loved by learners at thousands of companies


Course Description

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 basics

During 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 unittest

After 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.
For Business

GroupTraining 2 or more people?

Get your team access to the full DataCamp library, with centralized reporting, assignments, projects and more
Try DataCamp for BusinessFor a bespoke solution book a demo.

In the following Tracks

Python Developer

Go To Track

Python Programming

Go To Track
  1. 1

    Creating Tests with pytest

    Free

    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.

    Play Chapter Now
    Introduction to Testing in Python
    50 xp
    The first test suite
    100 xp
    pytest.raises
    100 xp
    Invoking pytest from CLI
    50 xp
    Run the test!
    100 xp
    Run with the keyword
    100 xp
    Applying test markers
    50 xp
    Markers use cases
    100 xp
    Failed tests with xfail
    100 xp
    Conditional skipping
    100 xp
  2. 2

    Pytest Fixtures

    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.

    Play Chapter Now
  3. 3

    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.

    Play Chapter Now
  4. 4

    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.

    Play Chapter Now
For Business

GroupTraining 2 or more people?

Get your team access to the full DataCamp library, with centralized reporting, assignments, projects and more

In the following Tracks

Python Developer

Go To Track

Python Programming

Go To Track

Datasets

DS_salariesEnergyGames

Collaborators

Collaborator's avatar
George Boorman
Collaborator's avatar
Arne Warnke
Collaborator's avatar
Katerina Zahradova
Alexander Levin HeadshotAlexander Levin

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.
See More

What do other learners have to say?

Join over 13 million learners and start Introduction to Testing in Python today!

Create Your Free Account

GoogleLinkedInFacebook

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.