1

I have a class with 3 tests and I am using pytest to run my tests with Selenium-Webdriver to perform UI operations.

class abc:
  def test_1(self):
      print("I am test_1 open browser and perform operations")
  def test_2(self):
      print("I am test_2 open browser and perform operations")
  def test_3(self):
      print("I am test_3 open browser and perform operations")

Each test opens Chrome browser instance to perform set of UI operations. Now I want to run all the above tests at single go. So ideally pytest should open three Chrome browser instances at the same time. (I read about xdist plugin, but I think that's used for running tests on different platforms)

Please provide your inputs.

Python_Novice
  • 170
  • 4
  • 16

1 Answers1

2

but I think that's used for running tests on different platforms

No, You can use xdist for one platform and for exactly what you have described.

What you need to do is, you just have to give command like this at run time:

pytest -n <NUM>

where <NUM> is the number of parallel workers.If you pass like,

pytest -n3

It would run 3 test in parallel.

Chanda Korat
  • 2,453
  • 2
  • 19
  • 23
  • To elaborate, `xdist` can be used for parallelizing any set of tests, regardless of whether they're on the same platform or different platforms, testing this string or that string, strawberry flavored or blueberry flavored. It just spins up n workers, and whenever a worker isn't running a test, gives it a test to run (unless there are no more tests). – Claire Nielsen Oct 19 '17 at 17:14
  • @Chanda - Thanks! that worked. Chlaire - I am not able to see the logs in my logs file when I am using -s with xdist. Also print statements have stopped working. Could you please let me know the resolution for this? – Python_Novice Nov 02 '17 at 07:26
  • @Python_Novice This the issue of pytest with xdist. Have a look at [this](https://stackoverflow.com/questions/36726461/how-to-print-output-when-using-pytest-with-xdist). Hope it would help you. – Chanda Korat Nov 02 '17 at 09:51