pytest-xdist indirect fixtures with class scope

685 views Asked by At

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 building the test object, I am using pytests indirection capability on fixtures to build them at test time rather than at collection. Some code I am using for testing can be found below.

#run.py
import pytest

@pytest.mark.parametrize("attribute",(
    ["pid1", ["pod1", "pod2", "pod3"]],
    ["pid2", ["pod2", "pod4", "pod5"]]
), indirect=True)
class TestSampleWithScenarios(object):
    @pytest.fixture(scope="class")
    def attribute(request):
        # checkout the pod here
        # build the device object and yield
        device = {}
        yield device
        # teardown the device object
        # release pod


    def test_demo1(self, attribute):
        assert isinstance(attribute, str)

    def test_demo2(self, attribute):
        assert isinstance(attribute, str)

My run command is currently pytest run.py -n 4 --dist=loadscope

When I do no use loadscope, all the tests are sent to their own worker. I do not want this because I would like to only build the device object once and use it for all related tests.

When I use loadscope, all the tests are executed against gw0 and I am not getting any parallelism.

I am wondering if there is any tweaks that I am missing or is this functionality not implemented currently.

0

There are 0 answers