How To Parametrize Pytests In Python (2 Min)

preview_player
Показать описание



Featured Tutorials:


Video Transcript:

Hi guys, this is Abhi from Gokcedb. In this video, you're going to learn how to parameterize PI tests in Python. Let's start by looking at the tests directory.

The second test file contains one test function to test the customer report to parameterize a test function. You have to use at PI test dot mark dot parameterize decorator for the test first query function. I'm defining four values for the keyword parameter.

On line 10, I'm asserting whether all these four keywords appear in the query output for the cash sales report query 1. When I run this test you can see that all four tests passed which means all of the four keywords that we passed as a parameter appear in the query output. Say I wanted to pass two parameters num and keyword.

To do that you have to pass the value in a list of tuples. Here I'm using the num parameter in the print function and the keyword parameter in the assert statement. When I execute this test file I see that all seven tests passed which mean all the keywords passed as a parameter appear in the query output.

If I change one of the keyword parameter values to XYZ, I would expect one of the tests to fail. Finally to export the test results click on the export test results button. There you have it.

Make sure you like, subscribe, and turn on the notification bell. Until next time.

# pass read_config fixture as the first argument
def test_first_query(read_config, keyword):
print("query output: ", output)
assert keyword in output

# pass read_config fixture as the first argument
def test_second_query(read_config, num, keyword):
print("num:", num, "query output: ", output)
assert keyword in output
Рекомендации по теме
join shbcf.ru