pytest-xdist icon indicating copy to clipboard operation
pytest-xdist copied to clipboard

Is there a way to run groups in parallel

Open sulaman9009 opened this issue 2 years ago • 3 comments

test.py

import pytest
import time

@pytest.mark.xdist_group(name="group1")
def test_1_1():
    time.sleep(5)
    assert True

@pytest.mark.xdist_group(name="group1")
def test_1_2():
    time.sleep(5)
    assert True
pytest -n auto --dist loadgroup test.py 

Is there a way to get group1 to run in parallel and take ~5s rather than ~10s it takes with the above setup

sulaman9009 avatar Dec 05 '23 12:12 sulaman9009

The purpose of "grouping" is to force tests to run in the same worker... if you want them to run in parallel, just don't put them into the same group.

What are you trying to accomplish?

nicoddemus avatar Dec 05 '23 16:12 nicoddemus

@nicoddemus, thanks for your response. For example, If you have multiple tests in a group dependent on one test in the same group, running with --dist loadgroup runs all tests in sequnece.

I know pytest-order is a different plugin but the below example could help explain my question better:

import pytest
import time

@pytest.mark.xdist_group(name="group1")
def test_1_1():
    time.sleep(5)
    assert True

@pytest.mark.xdist_group(name="group1")
@pytest.mark.order(after="test_1_1")
def test_1_2():
    time.sleep(5)
    assert True

@pytest.mark.xdist_group(name="group1")
@pytest.mark.order(after="test_1_1")
def test_1_3():
    time.sleep(5)
    assert True

@pytest.mark.xdist_group(name="group1")
@pytest.mark.order(after="test_1_1")
def test_1_4():
    time.sleep(5)
    assert True

3 tests are dependent on 1 (test_1_1) in a group but they could run in parallel after test_1_1 completes but currently with --dist=loadgroup all tests run in sequence.

is there a way to get ordered parallelism in a group?

sulaman9009 avatar Dec 06 '23 12:12 sulaman9009