setup_method 中的 pytest 夹具
pytest fixture in setup_method
我有一个 function
范围固定装置。
import pytest
@pytest.fixture(scope="function")
def some_fixture(req):
print "This is not the end"
return "okay"
是否可以通过某种方式调用 setup_method
中的夹具?
类似于以下代码片段...
class TestOne(object):
def setup_method(self, method, some_fixture): # this would give argument error
print "okay"
def test_one(self):
pass
我知道 fixture 的工作方式与 setup_method 相同,但我有一个非常极端的情况,我希望 fixture 在 setup_method 本身中执行。
您可以将 setup_method 标记为夹具,然后在测试中调用它。
class TestOne(object):
@pytest.fixture(scope="class")
def setup_method(self, method, some_fixture): # this would give argument error
print "okay"
def test_one(self, setup_method):
pass
我有一个 function
范围固定装置。
import pytest
@pytest.fixture(scope="function")
def some_fixture(req):
print "This is not the end"
return "okay"
是否可以通过某种方式调用 setup_method
中的夹具?
类似于以下代码片段...
class TestOne(object):
def setup_method(self, method, some_fixture): # this would give argument error
print "okay"
def test_one(self):
pass
我知道 fixture 的工作方式与 setup_method 相同,但我有一个非常极端的情况,我希望 fixture 在 setup_method 本身中执行。
您可以将 setup_method 标记为夹具,然后在测试中调用它。
class TestOne(object):
@pytest.fixture(scope="class")
def setup_method(self, method, some_fixture): # this would give argument error
print "okay"
def test_one(self, setup_method):
pass