How To Parametrize Pytests In Python (2 Min)
In this tutorial, you'll learn how to parametrize Pytests in Python using @pytest.mark.parametrize decorator.
—
Facebook: https://www.facebook.com/GokceDBsql
—
Featured Tutorials:
—
Connect MySQL In Python: https://www.youtube.com/watch?v=0qBctY82et0
—
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.
I have a conf test.py file and two test files. The conf test.py file contains a fixture function called read underscore config. The first test file contains two test functions to test the cache underscore sales report.
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
@pytest.mark.first_query
@pytest.mark.parametrize("keyword", ["SELECT", "FROM", "WHERE", "XYZ"])
def test_first_query(read_config, keyword):
output = read_config.get("query", "cash_sales_report_query1").replace("\"", "")
print("query output: ", output)
assert keyword in output
# pass read_config fixture as the first argument
@pytest.mark.second_query
@pytest.mark.parametrize("num, keyword", [(1, "SELECT"), (2, "FROM"), (3, "WHERE")])
def test_second_query(read_config, num, keyword):
output = read_config.get("query", "cash_sales_report_query2").replace("\"", "")
print("num:", num, "query output: ", output)
assert keyword in output
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «How To Parametrize Pytests In Python (2 Min)», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.