我正在试用Atom编辑器,想知道如何使用键盘快捷键运行Python单元测试。
安装
单元测试示例test.py
编写单元测试并将其另存为test.py
。
import unittest
class MyTest(unittest.TestCase):
def test_pass(self):
pass
def test_fail(self):
call_method_that_does_not_exist()
if __name__ == '__main__':
unittest.main()
运行单元测试
控制台输出
因为单元测试test_fail
将失败,所以这将是控制台输出:
E.
======================================================================
ERROR: test_fail (__main__.MyTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/Lernkurve/Desktop/PythonDemos/a.py", line 9, in test_fail
call_method_that_does_not_exist()
NameError: global name 'call_method_that_does_not_exist' is not defined
----------------------------------------------------------------------
Ran 2 tests in 0.000s
FAILED (errors=1)
[Finished in 0.047s]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句