Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在&;之前运行特定代码;在Python中的每个单元测试之后_Python_Unit Testing - Fatal编程技术网

如何在&;之前运行特定代码;在Python中的每个单元测试之后

如何在&;之前运行特定代码;在Python中的每个单元测试之后,python,unit-testing,Python,Unit Testing,以下是我的测试文件的结构 类 设置 test01 test02 test03 拆卸 我需要在每次测试前后运行特定的代码 以前,我可以从设置中调用该代码。 但是在考试之后,我不知道该怎么做。 显然,从teardown调用代码对最后一个测试有效,但是如何让它在这两个测试之间运行呢?假设您正确地使用了从unittest.TestCase派生的类,那么setUp方法在每个测试之前运行,而teardown方法在每个测试之后运行。因此,将代码放在这两种方法中是完全可行的。请参阅还有一种设置方法,用于在测试之

以下是我的测试文件的结构


设置
test01
test02
test03
拆卸

我需要在每次测试前后运行特定的代码

以前,我可以从设置中调用该代码。 但是在考试之后,我不知道该怎么做。
显然,从teardown调用代码对最后一个测试有效,但是如何让它在这两个测试之间运行呢?

假设您正确地使用了从
unittest.TestCase
派生的类,那么
setUp
方法在每个测试之前运行,而
teardown
方法在每个测试之后运行。因此,将代码放在这两种方法中是完全可行的。

请参阅还有一种设置方法,用于在测试之前处理调用代码。