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 fixture
In the previous lesson, we created these two test functions which repeated this part of code i.e. generating in the report, opening the file, and loading in the data. In this lesson, we learned about pytest fixtures and how to create them to share some state slash data among our test functions like this report data so let's go ahead and learn about the same so what is a pytest fixture well it is nothing but a simple function which returns a piece of data like this so to define a pytest fixture we'll go ahead and import the pytest module and then start with our function definition now go ahead and name the function as you'd like the data to be and in this case it will be report json and now to actually make this function a fixture we will decorate it using the pytest dot fixture decorator now our function is a decorator which can be used to share our report data among our test functions. So let's go ahead and perform the things which we just did inside of our functions that is…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.