有没有办法在 IDLE 中直接运行 PyUnit(unittest 模块)单元测试?
我问是因为我有一个简短的测试模块,当我使用 Cygwin shell 中的 python mymodule.py 运行它时,我通过了所有测试,但是当我从 IDLE 使用 Run->Run Module 时,测试通过了,但是我得到了一个异常(系统退出:假)。
例如,这里有一个示例测试模块来重现这个:
#!/usr/bin/python
import unittest
class fooTests(unittest.TestCase):
def setUp(self):
self.foo = "bar"
def testDummyTest(self):
self.assertTrue(True)
def testDummyTestTwo(self):
self.assertEquals("foo", "foo")
def tearDown(self):
self.foo = None
if __name__ == '__main__':
unittest.main()
当我使用 python fooTests.py 从 Cygwin shell 运行它时,它会产生:
$ python fooTests.py
..
----------------------------------------------------------------------
Ran 2 tests in 0.000s
OK
但是,当我在 IDLE 中编辑 fooTests.py 并执行 Run -> Run Module 时,IDLE 生成的新 Python Shell 会产生:
>>> ================================ RESTART ================================
>>>
..
----------------------------------------------------------------------
Ran 2 tests in 0.031s
OK
Traceback (most recent call last):
File "C:\Some\path\info\I\shortened\fooTests.py", line 20, in <module>
unittest.main()
File "C:\Python26\lib\unittest.py", line 817, in __init__
self.runTests()
File "C:\Python26\lib\unittest.py", line 865, in runTests
sys.exit(not result.wasSuccessful())
SystemExit: False
>>>
我做错了什么,产生这个回溯,特别是我该如何修复它,以便我可以在 IDLE 中执行 Run-> Run Module(或 F5)来快速运行单元测试?
(这肯定是一个简单的问题,但我快速弄清楚它的尝试被证明是徒劳的。)