Questions tagged [pytest-xdist]

pytest-xdist is a pytest plugin which allows test execution in parallel. Paralellization works both by running a configurable number of processes on the same host, and across multiple hosts. It also supports running tests on multiple platforms and Python interpreters in parallel. Additionally, it supports automatic re-running of failed tests.

Reference:

88 questions
4
votes
0 answers

How to collect values from a parametrized test function in a single pytest-xdist run

Using pytest-xdist I run a parametrized test function that has a variable I am interested in. I would like to store a value of the variable in a separate object and use that object later on to compose a test report. I tried to use a session scope…
neofluar
  • 41
  • 4
4
votes
2 answers

Pytest Xdist parallel execution, prevent recreating the database

I'm trying to speed up the Selenium tests in my python Django web application by using parallel execution of 4 threads (-n=4) Of the first 4 tests, 3 give the following error: [test setup] [Test Error Output] Got an error creating the test database:…
Cloud
  • 458
  • 1
  • 13
  • 34
4
votes
1 answer

How to run setup in each pytest-xdist process

When my test runner starts, I want to set some stuff up (adjust sys.path, add some environment variables, start some global fixtures). What hook can I use to make these changes in each xdist process that is spawned? I've tried overloading a couple…
dbn
  • 13,144
  • 3
  • 60
  • 86
3
votes
0 answers

Test fails when run in parallel in python selenium via pytest xdist but works well in sequence

When I run the below code with pytest .\tests\GET\test_setupFunc.py it works perfectly i.e. setup(my_fixture) function run once then test_one and test_two if i run it parallely using pytest-xdist using this pytest .\tests\GET\test_setupFunc.py…
Gaurav Khurana
  • 3,423
  • 2
  • 29
  • 38
3
votes
2 answers

How can I resolve an error running pytest in parallel via xdist in bitbucket pipelines

We execute our unit tests for our python repo within a bitbucket pipeline. Recently we started using the pytest-xdist (https://pypi.org/project/pytest-xdist/) package and successfully run our unit tests in parallel when running locally via the…
3
votes
0 answers

Running tests on remote machine and capture output using pytest

If I execute tests on local machine, I can see the console output from the test case. However, the console output is not captured while running tests on remote machine using pytest. Here is the sample test case - test_sample.py import os import…
Abhishek Kulkarni
  • 3,693
  • 8
  • 35
  • 42
3
votes
1 answer

pytest-parallel not honouring module-scope fixtures

Suppose I have the below test cases written in a file, test_something.py: @pytest.fixture(scope="module") def get_some_binary_file(): # Some logic here that creates a path "/a/b/bin" and then downloads a binary into this path …
user1452759
  • 8,810
  • 15
  • 42
  • 58
3
votes
0 answers

pytest-xdist indirect fixtures with class scope

I have some complicated and heavy logic to build a test object and the tests are very long running. They are integration tests and I wanted to try and parallelize them a bit. So i found the pytest-xdist library. Because of the heavy nature of…
Cameron Hurst
  • 263
  • 1
  • 13
3
votes
1 answer

How to access a shared resource with pytest-xdist?

I want to access a list that contains all the account credentials to provide them to each separate thread in pytest-xdist. How do I achieve that? As far as I know, pytest-dist, for each thread started, it is a separate session of tests and they…
Milin
  • 183
  • 13
3
votes
2 answers

Pytest Xdist different tests were collected error

First time posting here, and I've tried to search these past 2 days for a solution to my problem with xdist. When I try to run with n=2 or anything higher, I sometimes (I say sometimes because it works randomly) get an error along the lines of…
Jace Romero
  • 31
  • 1
  • 4
3
votes
0 answers

pytest-xdist running 1 test per slave

My scenario consists of a server that notify to attached websockets when some event occurs. The websocket query params specify for which kind of events the client should be notified. I have a set of predefined events for the notification, and a set…
Teudimundo
  • 2,610
  • 20
  • 28
2
votes
0 answers

Pytest-xdist - how can I know which worker collected which items (tests)?

In pytest I use fixture request in order to get collected itmes by using request.session.items, which gives me function items. I'm running pytest using xdist with worker number > 1 and I want to know, before the first test runs, which worker will…
caffein
  • 303
  • 1
  • 10
2
votes
1 answer

Can I get pytest-xdist to parallelize test *files* and not test *methods*?

I have a large test suite that contains thousands of tests of an information extraction engine. There are about five hundred inputs, and I have to extract 10-90 items of information from each input. For maximal transparency, I test each item from…
Kilian Foth
  • 13,904
  • 5
  • 39
  • 57
2
votes
0 answers

How can I know from inside a pytest hook if pytest-xdist is enabled?

I want to write a pytest session finish hook that is aware if the xdist plugin has been activated (for example if the -n option has been passed). Is there an official / stable way to do this ? I found a way to identify if this is a xdist worker, but…
smarie
  • 4,568
  • 24
  • 39
2
votes
1 answer

Is pytest-xdist thread safe with singleton

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…
tetienne
  • 369
  • 3
  • 13