From the course: Playwright Python and Pytest for Web Automation Testing: Master Modern Web Testing with Playwright and Pytest in Python

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Pytest parametrize

Pytest parametrize

In this lesson, we'll go ahead and learn how to parameterize a test case to provide it a set of input and output data. So here I have a root function which takes a number and returns the half hour of that number that is its root. And we'll write test case for the same. So let's go ahead and create our test module. So test root.py inside of the same we will go ahead and import the root function. Now we'll go ahead and define our test function. And then usually we will go ahead and assert the root of 25 to be equals to 5 like this. Of course, this will work. But if we want to provide a set of values, that is, let's say I have a set of values like hundreds, root is 10. Then we have, let's say, 36 and its root is six. Then we have 25. Its root is five, 16, and its root is four. And similarly, we can keep adding more input and output data. Now to give this data to our test case, we will parametrize the same. To do that, we will use the PyTest parametrize decorator. So let's go ahead and…

Contents