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.

Fixture scope

Fixture scope

It's great that we got rid of the code duplication from our test functions and extracted the loading inside our report json fixture. Now if we take a look at the logs, you will notice that when we run the first test, we request the fixture and return the data. The same happens for the second test. What this means is that whenever we request for this fixture, this block of code got run. Which means that we load the report or generate it twice, open the file twice and load in the data twice as well for these two test functions. Now if we were have more functions, let's say 10 plus, then it will run for that amount as well, which is not desirable. What we'd like to happen is that this report JSON can only run once per our test session. That is for one time, it will go ahead and generate the report. Then for one time, it will go ahead and load in the data. And then that once loaded data could be shared amongst all the test functions. Well, we can achieve the same using our fixture…

Contents