How to run Python unit test using Atom editor?

I tried the Atom editor and wondered how I can run Python unit tests with a keyboard shortcut.

+7
source share
3 answers

Installation

  • Install Atom Editor
  • Install the Script package as follows:

    a) Launch Atom

    b) Press Ctrl + Shift + P , type โ€œinstall packages and themesโ€ and press Enter to open the package view

    c) Find the "script" and install the package

Unit test example test.py

  1. Write 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

  1. Now press Ctrl + I to run the Python script ( see documentation )

Console exit

Since unit test test_fail will fail, this will exit to the console:

 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] 
+12
source

You can use the Atom Python Test plugin. It supports:

  • Run the test under the cursor
  • Run all module tests
  • Running doc tests

It also supports the addition of additional arguments to verify execution and also allows unitttest.TestCase to be run.

+3
source

Check out the link at https://atom.io/packages/atom-python-test, itโ€™s very easy there step by step for the Atom IDE

0
source

Source: https://habr.com/ru/post/1211304/


All Articles