擅长:python、mysql、java
<p>你不需要嘲笑任何东西;在运行每个测试之前,您只需要确保全局变量处于已知状态。另外,使用<code>from main import *</code>在测试模块中创建一个名为<code>feedback</code>的<em>新的</em>全局,与<code>setFeedback</code>正在修改的<code>main.feedback</code>不同</p>
<pre><code>import main
class TestMain(unittest.TestCase):
def setUp(self):
main.feedback = False
def test_setFeedback(self):
self.assertFalse(feedback)
main.setFeedback('y')
self.assertTrue(feedback)
</code></pre>