[英]How to run a Python unit test with the Atom editor?
我正在尝试使用Atom编辑器,并想知道如何使用键盘快捷键运行Python单元测试。
Installation 安装
Install the Script package like this: 像这样安装脚本包:
a) Start Atom a)启动Atom
b) Press Ctrl + Shift + P , type "install packages and themes" and press Enter to open the package view b)按Ctrl + Shift + P ,键入“安装包和主题”,然后按Enter打开包视图
c) Search for "script" and install the package c)搜索“脚本”并安装包
Unit test example test.py 单元测试示例test.py
Write a unit test and save it as 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()
Run unit test 运行单元测试
Console output 控制台输出
Because the unit test test_fail
will fail, this will be the console output: 因为单元测试
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]
You could use the Atom Python Test plug-in. 您可以使用Atom Python Test插件。 It supports:
它支持:
It also supports adding additional arguments to test execution and allows to run unitttest.TestCase too. 它还支持添加额外的参数来测试执行,并允许运行unitttest.TestCase。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.