遵循以下模式:https://docs.pytest.org/en/latest/xunit_setup.html
如何使用fixture_foo
并将其注入setup_method
class TestClassX:
def setup_method(self, method):
# I need `fixture_foo` here
def teardown_method(self, method):
# N/A
def test_cool(self, fixture_foo):
# Why can `fixture_foo` be injected here and not in `setup_method`?
答案 0 :(得分:0)
您必须切换到Houses.color = blue
样式的夹具才能访问夹具。与pytest
等效的方法如下:
setup_method
该@pytest.fixture
def f():
return 'ohai'
class Test:
@pytest.fixture(autouse=True)
def setup_method_fixture(self, request, f):
self.f = f
self.method_name = request.function.__name__
def test(self):
assert self.method_name == 'test'
assert self.f == 'ohai'
固定装置将在类中为每种测试方法调用一次