Reputation: 21562
I'm trying out the Atom editor and was wondering how I can run Python unit tests with a keyboard shortcut.
Upvotes: 7
Views: 9207
Reputation: 1964
You could use the Atom Python Test plug-in. It supports:
It also supports adding additional arguments to test execution and allows to run unitttest.TestCase too.
Upvotes: 3
Reputation: 21562
Installation
Install the Script package like this:
a) Start Atom
b) Press Ctrl+Shift+P, type "install packages and themes" and press Enter to open the package view
c) Search for "script" and install the package
Unit test example test.py
Write a unit test and save it as 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:
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]
Upvotes: 13