Python unit test library Nose option introduction-19 types-

A list of options for the nosetests command of the python unit test tool Nose. Although it is called a list, I was exhausted on the way, so it is my own discretion, but it is arranged from the top in the order of frequent use. I can't put the basic usage.

1. Run all tests (run without anything)

Perform all file test cases that match the nose naming convention

nosetests

2. Run the test in a specific file (run with the path to the test file)

nosetests test_settings.py

3. Run only specific test cases (FILEPATH: ClassName.methodName)

nosetests test_settings.py #Run tests in a specific file
nosetests test_settings.py:SettingsApiTestCase #Run tests in a particular class in a particular file
nosetests test_settings.py:SettingsApiTestCase.test_get_settings #Run tests for specific methods in specific classes in specific files

4. Run the test that failed the last run (--failed)

nosetests --failed

5. Parallel execution in multiple processes (--processes = NUM)

Specify the number of startup processes.

nosetests --processes=4

6. Test execution process timeout (--process-timeout = SECONDS)

The default is 10 seconds

nosetests --process-timeout=10

7. Output stdout (-s, --nocapture)

In the example below, if you put print () in test_settings.py, the contents will be output.

nosetests test_settings.py -s

8. Detailed test result display (-v, --verbosity = VERBOSITY)

nosetests sample_test.py -v
nosetests sample_test.py --verbosity=2

9. Simplify test result display (-q)

nosetests test_settings.py -q

10. Collect only test case names without running tests (--collect-only)

Use it with the -v option to output all test case names.

nosetests --collect-only -v

11. Specifying working directory (-w)

In the case of the example below, test_settings.py under ./tests/ will be executed.

nosetests test_settings.py -w ./tests/

12. Specifying the config file (-c)

Read .noserc or nose.cfg in home directory by default. Option to specify this. To prevent reading anything ʻexport NOSE_IGNORE_CONFIG_FILES = 1`

nosetests test_settings.py -c ./config.ini

13. Run tests in a specific file # 2 (--tests)

Specify multiple test files separated by commas

nosetests --tests=test_settings.py,test_login.py
nosetests test_settings.py test_login.py #This is the same

14. Execute the file that matches the regular expression (-m REGEX, --match = REGEX, --testmatch = REGEX)

By default, ((?: ^ | \ B_ \ .-]) [Tt] est) is specified, so files starting with test etc. are executed. In the example below, test_settings.py will be executed.

nosetests -m .*setting.*

15. Exclude test files with regular expressions (-I REGEX, --ignore-files = REGEX)

In the example below test_settings.py will not be executed

nosetests -I .*setting.*

16. Exclude test cases with regular expressions (-e REGEX, --exclude = REGEX)

In the example below, test case test_get_settings1 is skipped and test_get_settings2 is executed

nosetests -e .*settings1.*

17. Specify the name of the test file to be additionally executed with a regular expression (-i REGEX, --include = REGEX)

In the example below, since -m aaaaaaaaaaaaa.py is executed, only the one that exactly matches ʻaaaaaaaaaaaaa.py is executed, but since -i. * Setting. * `Is specified, test_settings.py Will be executed

nosetests -m aaaaaaaaaaaaa.py -i .*setting.*

18. Run the test until it fails, stop the test if it fails (-x, --stop)

nosetests -x

19. Disable test skipping (--no-skip)

If you add @ unittest.skip ("skipping this one ") etc., the test case will be skipped, but I think it is an option to prevent this from being skipped, but if you execute it, the skip itself will be skipped and when the test result is displayed It seems that ʻOK (SKIP = 1) just becomes ʻOK? ?? ??

nosetests test_settings.py --no-skip

Recommended Posts

Python unit test library Nose option introduction-19 types-
python unit test template
Introduction to Python Numerical Library NumPy
Unit test log output with python
[Python] What I did to do Unit Test
Python & Machine Learning Study Memo ②: Introduction of Library
Introduction of Python Imaging Library (PIL) using HomeBrew
Python 3.6 email library
Introduction of Python
Python ast library
numpy unit test
Python Integrity Test
Python Library notes
Python unit tests
Introduction of Python
Write code to Unit Test a Python web app
[Introduction to Python] Basic usage of the library matplotlib