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.

Run tests in parallel

Run tests in parallel

in this lesson we will learn how to run multiple tests at once that is running tests in parallel now by default pytest runs our test sequentially that is it runs the test one by one now here I have a test directory with a total of five test files. Now if I go ahead and run the tests using pytest command in the test directory, pytest will collect all of the files and run the test one by one. So let's wait for all of them to finish. Now you can see the total time taken to finish these 6 items was 27.51 seconds. Now it's alright because we only ran 6 items. But if we had more, let's say tens or even hundreds of tests, then this figure will go up pretty quickly. So instead of running a test one by one, what we can do is run multiple at once. To do that, we can make use of the threads of our CPU. As modern day CPUs post multiple threads, mine has 12. So let's go ahead and learn how to use them. To do that, we'll require a pytest plugin. So let's install the same using pip inside of our…

Contents