I have two Pytest classes: one test class is very fast and the other is slower, parametrizing itself with a function call and reusing that resource across multiple tests.
My problem is that, when running the quicker test via pytest test.py -k "Quick", I have to wait for the slower test to be parametrized before the specified test will be run.
class TestQuick:
def test_quick(self): pass
@pytest.mark.parametrize('num', get_nums())
class TestSlow
def test_1(self, num): pass
def test_2(self, num): pass
def get_nums():
inputs = range(100)
with multiprocess.Pool(10) as pool:
return list(pool.map(IO_fn, # takes a lot of time
inputs))
I have tried using @pytest.mark.parametrize('num', get_nums(), indirect=True), but I couldn't get this to work.
I also tried using @pytest.fixture(scope='class') on IO_fn, which is almost there except for:
- I lose the crucial ability to speed up collection of
numsusing multiprocessing. - I want my test output to be grouped by
TestSlow/num/testrather than just a flat directory ofTestSlow/test.