Nose Testing Framework
Nose extends unittest to make testing easier, providing a simpler test discovery and running mechanism. Its last major release was 1.3.7 in 2015, and the project is no longer actively maintained. Users are strongly encouraged to migrate to modern alternatives like pytest.
Warnings
- breaking Nose 1.3.7, the last released version, was developed primarily for Python 2. While it might partially function in some Python 3 environments, it is not officially supported and will likely encounter errors or unexpected behavior with modern Python 3 versions (3.6+).
- deprecated The `nose` project is officially unmaintained and abandoned. Its GitHub repository prominently displays a warning encouraging users to switch to `pytest`. Expect no further updates, bug fixes, or security patches.
- gotcha Nose's test discovery mechanism (looking for `test_` prefixes in filenames, classes, and methods) can sometimes lead to unintended test execution or missed tests if not consistently applied. It also had specific rules for how it interacted with `__init__.py` files.
Install
-
pip install nose
Imports
- run
import nose nose.run()
- TestCase
from unittest import TestCase
Quickstart
import nose
from unittest import TestCase
class MyTest(TestCase):
def test_something(self):
self.assertEqual(1, 1)
if __name__ == '__main__':
# To run this directly without the `nosetests` command:
# nose.run()
# For programmatic execution, typically you'd run from command line.
print("Run with: nosetests")
# Example of what `nosetests` would do if run programmatically:
# nose.run(argv=['', '--verbose', __file__])