2

I'm bootstrapping a new Selenium project using Python. Coming from the Java world, I used to wrap the Webdriver instance within a ThreadLocal. This way I'm sure when my tests are run in parallel with TestNG, my Webdriver sessions will be isolated and not shared between thread.

I want to implement the same behavior in Python. For the singleton, I can use a MetaClass. To run the test in paralel, I can use pytest-xdist. But can you tell me if both are compatible, meaning my session will not be mixed?

MrBean Bremen
  • 7,785
  • 3
  • 13
  • 30
tetienne
  • 139
  • 1
  • 10

1 Answers1

0

If you wish to have parallelism with the xdist and be sure everything is fine in terms of isolation use the --boxed flag like in sample below:

# Execute tests in [N] forked subprocess. Won't work on windows
pytest --dist=each --tx [N]*popen//python=python --boxed

Or as an alternative you can use socker server for code execution or even ssh. See more on that topic here: https://stackoverflow.com/a/56390281/2067976.

Good luck !

Andriy Ivaneyko
  • 15,838
  • 3
  • 43
  • 65
  • Thx for your explanation. I didn't know the boxed flag. But finally, I removed my singleton and used the fixture feature of Pytest and pass a Webdriver instance to each test. It's less error-prone. – tetienne Jun 27 '19 at 07:15