1

I'm using Pytest, and having the following structure of tests :

ClassA.py

---------------test_a

---------------test_b

---------------test_c

And Also

ClassB.py

---------------test_d

---------------test_e

---------------test_f

I'm running my tests via terminal command (i.e.: pytest -v -s ClassA.py)

My question: Is there a way to run ClassA & ClassB in parallel (2 instances you might say), while maintaining order on each class - separately? Meaning I want all tests from ClassA will run on 1st browser instance, and all tests from ClassB will run on a different instance.

I'm also familiar with parallel test execution using the 'pytest-xdist' plug-in. But once using it the test cases that are in ClassA and ClassB are executed in the mixed order, so that is not good for me.

EDITED: My main purpose is to avoid from test_a running on a separate browser instance of test_b. I would like the tests on each class to run on the same browser instance

dima edunov
  • 59
  • 1
  • 9

1 Answers1

0

Yes, it is possible. Mark the test with order using pytest-order plugin and use pytest n 2 --dist loadfile. It will run Class A test in one browser and then initiate ClassB test in 2nd browser. Make sure you are passing the driver instance from conftest with the scope set to class

Atique
  • 45
  • 6
  • I don't think he would need pytest-order plugin. Defining the browser in classA and classB and using `--dist loadfile` should be enough in this case. – SilentGuy Aug 09 '21 at 22:34