我有两个测试用例模块 TestClassA,TestClassB 。在TeseClass A中的test_1_that_needs_resource_a上,我正在使用fixture,所以我可以在执行testcase之前调用resource_a并传递参数。如何在TestClassB中的setup_class上使用相同的fixture,以便所有测试用例 在TestClassB中,因此可以在TestClassB中的所有测试用例之前调用fixture一次
import pytest
@pytest.fixture(scope='function')
def resource(request):
print('resources_a_setup()')
return request.param
class TestClassA:
@classmethod
def setup_class(cls):
print('\nsetup_class()')
@classmethod
def teardown_class(cls):
print('\nteardown_class()')
@pytest.mark.parametrize('resource', [dict(), dict(name=1)], indirect=['resource'])
def test_1_that_needs_resource_a(self, resource):
assert resource == dict()
print(f'\ntest_1_that_needs_resource_a(), {resource}')
class TestClassB:
## I would like to call resource fixture with passing some parameter on setup_class here
@classmethod
def setup_class(cls):
print('\nsetup_class()')
@classmethod
def teardown_class(cls):
print('\nteardown_class()')
def test_1_that_needs_resource_a(self):
print('\ntest_1_that_needs_resource_a()')