擅长:python、mysql、java
<p>类似问题的答案在这里更有帮助:</p>
<p><a href="https://stackoverflow.com/questions/30656864/how-to-a-run-a-specific-code-before-after-each-unit-test-in-python?rq=1">How to a run a specific code before & after each unit test in python</a></p>
<p>我使用了python setUpClass方法
<a href="https://docs.python.org/2/library/unittest.html#unittest.TestCase.setUpClass" rel="nofollow noreferrer">https://docs.python.org/2/library/unittest.html#unittest.TestCase.setUpClass</a></p>
<pre><code>setUpClass()
A class method called before tests in an individual class are run. setUpClass is called with the class as the only argument and must be decorated as a classmethod():
@classmethod
def setUpClass(cls):
...
</code></pre>
<p>我这样做我的测试:</p>
^{pr2}$