如何为所有鼻子测试执行一次设置和拆卸功能?
def common_setup():
#time consuming code
pass
def common_teardown():
#tidy up
pass
def test_1():
pass
def test_2():
pass
#desired behavior
common_setup()
test_1()
test_2()
common_teardown()
Run Code Online (Sandbox Code Playgroud)
请注意,在将点替换为并添加行后,存在一个类似的问题,其答案不适用于 python 2.7.9-1、python-unittest2 0.5.1-1 和 python-nose 1.3.6-1 。不幸的是,我的声誉太低,无法对此发表评论。passimport unittest