O'Reilly logo

Python Testing with pytest by Brian Okken

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Parametrized Testing

Sending some values through a function and checking the output to make sure it’s correct is a common pattern in software testing. However, calling a function once with one set of values and one check for correctness isn’t enough to fully test most functions. Parametrized testing is a way to send multiple sets of data through the same test and have pytest report if any of the sets failed.

To help understand the problem parametrized testing is trying to solve, let’s take a simple test for add():

 import​ pytest
 import​ tasks
 from​ tasks ​import​ Task
 
 
 def​ test_add_1():
 """tasks.get() using id returned from add() works."""
  task = Task(​'breathe'​, ​'BRIAN'​, True) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required