Skip to main content

Unit Testing for Data Science in Python

4.3+
20 reviews
Intermediate

Learn how to write unit tests for your Data Science projects in Python using pytest.

Start Course for Free
4 Hours17 Videos55 Exercises
28,213 Learners

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.

Loved by learners at thousands of companies


Course Description

Every data science project needs unit testing. It comes with huge benefits - saving a lot of development and maintenance time, improving documentation, increasing end-user trust and reducing downtime of productive systems. As a result, unit testing has become a must-have skill in the industry, used by almost every company. This course teaches unit testing in Python using the most popular testing framework pytest. By the end of this course, you will have written a complete test suite for a data science project. In the process, you will learn to write unit tests for data preprocessors, models and visualizations, interpret test results and fix any buggy code. You will also learn advanced concepts like TDD, test organization, fixtures and mocking so that you can test your own data science projects properly.
  1. 1

    Unit testing basics

    Free

    In this chapter, you will get introduced to the pytest package and use it to write simple unit tests. You'll run the tests, interpret the test result reports and fix bugs. Throughout the chapter, we will use examples exclusively from the data preprocessing module of a linear regression project, making sure you learn unit testing in the context of data science.

    Play Chapter Now
    Why unit test?
    50 xp
    How frequently is a function tested?
    50 xp
    Manual testing
    100 xp
    Write a simple unit test using pytest
    50 xp
    Your first unit test using pytest
    100 xp
    Running unit tests
    50 xp
    Understanding test result report
    50 xp
    What causes a unit test to fail?
    50 xp
    Spotting and fixing bugs
    100 xp
    More benefits and test types
    50 xp
    Benefits of unit testing
    50 xp
    Unit tests as documentation
    50 xp
  2. 2

    Intermediate unit testing

    In this chapter, you will write more advanced unit tests. Starting from testing complicated data types like NumPy arrays to testing exception handling, you'll do it all. Once you have mastered the science of testing, we will also focus on the arts. For example, we will learn how to find the balance between writing too many tests and too few tests. In the last lesson, you will get introduced to a radically new programming methodology called Test Driven Development (TDD) and put it to practice. This might actually change the way you code forever!

    Play Chapter Now
  3. 3

    Test Organization and Execution

    In any data science project, you quickly reach a point when it becomes impossible to organize and manage unit tests. In this chapter, we will learn about how to structure your test suite well, how to effortlessly execute any subset of tests and how to mark problematic tests so that your test suite always stays green. The last lesson will even enable you to add the trust-inspiring build status and code coverage badges to your own project. Complete this chapter and become a unit testing wizard!

    Play Chapter Now
  4. 4

    Testing Models, Plots and Much More

    In this chapter, You will pick up advanced unit testing skills like setup, teardown and mocking. You will also learn how to write sanity tests for your data science models and how to test matplotlib plots. By the end of this chapter, you will be ready to test real world data science projects!

    Play Chapter Now

In the following tracks

Python ProgrammerPython Programming

Collaborators

Collaborator's avatar
Hillary Green-Lerman
Collaborator's avatar
Hadrien Lacroix

Prerequisites

Intermediate Python
Dibya Chakravorty HeadshotDibya Chakravorty

Senior Python Developer, TECH-5

Dibya is currently developing a test automation framework for a leading German car manufacturer. He thinks that high-quality, well-tested code is far more valuable than code that only seems to work.

His other passion is Deep Reinforcement Learning, because it is a step towards Strong AI.

Dibya has a deep love for Python. He co-organizes the Python meetup group in Munich. He also maintains a website that helps learners find the best Python books in any topic.

Want to connect with him? Here is his LinkedIn profile.

See More

Don’t just take our word for it

*4.3
from 20 reviews
55%
25%
15%
5%
0%
Sort by
  • Iván S.
    2 months

    Super clear and useful

  • Esteban A.
    5 months

    Great application, maybe more functions or indepth

  • Jesus V.
    6 months

    I believe every chapter delivers value because of the concrete techniques the autor shows. Really good reference for practical usage. I used all the decorators and the flow (setup, test, tear down) to some of the test of my current job

  • Lyndon H.
    8 months

    I was starting from a print("I am here") approach to testing and I found this course very informative as I work with twenty year olds who have been taught this in their formative years.

  • Maciej G.
    9 months

    pytest is useful, it can be a great data validation tool in datascience, an interesting course will allow me to refresh my pytest knowledge

"Super clear and useful"

Iván S.

"Great application, maybe more functions or indepth"

Esteban A.

"I believe every chapter delivers value because of the concrete techniques the autor shows. Really good reference for practical usage. I used all the decorators and the flow (setup, test, tear down) to some of the test of my current job"

Jesus V.

Join over 12 million learners and start Unit Testing for Data Science 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.