0
@pytest.mark.django_db
class TestClass():

    def do_setup(self):
        # do setup

    def test_a(self):
        # do something

    def test_b(self):
        # do something

在 test_a 和 test_b 测试用例运行之前,我需要调用 do_setup() 。我正在使用 pytest-django 框架。

请帮忙。

提前致谢

4

1 回答 1

0

使用方法/功能级别设置拆解

def setup_method(self, method):
    """ setup any state tied to the execution of the given method in a
    class.  setup_method is invoked for every test method of a class.
    """

def teardown_method(self, method):
    """ teardown any state that was previously setup with a setup_method
    call.
    """

参考http://pytest.org/latest/xunit_setup.html#method-and-function-level-setup-teardown

于 2016-02-06T05:58:47.753 回答