nose2
nose2 is the successor to Nose, developed to extend Python's standard `unittest` module with a rich plugin ecosystem to ease the testing process. It acts as a popular test runner that automatically discovers and executes unit tests within a project. The current version is 0.16.0. It follows a 0.MAJOR.MINOR versioning scheme, where major releases introduce new functionality or breaking changes, and minor releases focus on bug fixes or small features.
Warnings
- breaking nose2 is a distinct project from the original `nose` and is not fully backward compatible. `nose` plugins will not work with `nose2` without significant rewriting. Features like package-level fixtures supported by `nose` are not supported in `nose2`.
- breaking Python 2 is no longer supported; the last line supporting Python 2 was 0.12.x. As of version 0.16.0, support for Python 3.8 has also been removed. nose2 now requires Python >=3.9.
- deprecated The built-in `coverage` plugin is deprecated as of version 0.16.0 and is no longer tested on newer Python versions. It will be removed in a future release.
- gotcha `nose2` relies heavily on its plugin system; if no plugins are loaded (e.g., using `--no-plugins`), `nose2` effectively does nothing.
- gotcha When using `test_suite='nose2.collector.collector'` with `python setup.py test`, `nose2` 'hijacks' the test running process, bypassing the standard `unittest` test result and runner. This might cause incompatibilities with certain packages or custom setups.
Install
-
pip install nose2
Imports
- nose2
import nose2
- main
import nose2.main nose2.main()
Quickstart
import unittest
class MyTests(unittest.TestCase):
def test_addition(self):
self.assertEqual(1 + 1, 2)
def test_subtraction():
assert 5 - 2 == 3
# Save this as `test_math.py`
# To run from the command line: `nose2`