Motivation

As a data scientist, it is important to make sure your functions work as expected. A good practice is to write a small function then test your function with unit testing.

Rather than trying to debug a big chunk of code, it is better to break your code down into smaller pieces and make sure the smaller pieces work.

Pytest is the ideal framework that makes it easy to write small tests in Python. I covered the benefits of unit testing and how to get started with pytest here. In the last article, I have shown how to:

  • Test one function with multiple tests
  • Combine multiple tests into one test function
  • Test one function at a time
  • Test different functions using the same data
  • Structure your projects

In this article, I will show you how to:

  • Filter warnings
  • Print the output of the function being tested
  • Benchmark your code
  • Repeat a single test for a specific number of times

Let’s get started!

#python-programming #programming #python #data-science

4 Lessor-Known Yet Awesome Tips for Pytest
2.95 GEEK