A testing framework that extends unittest with plugins and enhanced discovery capabilities
npx @tessl/cli install tessl/pypi-nose2@0.15.0A powerful Python testing framework that extends the built-in unittest module with enhanced discovery capabilities, parameterized testing, BDD-style test writing, extensive plugin system, and advanced features like coverage reporting, multiprocessing, and custom test runners.
pip install nose2import nose2Test runner imports:
from nose2 import main, discoverTesting tools and utilities:
from nose2.tools import params, cartesian_params, such
from nose2.tools.decorators import with_setup, with_teardownPlugin development:
from nose2.events import Plugin
from nose2.session import Session# Simple test discovery and execution
import nose2
nose2.discover()
# Custom test program
from nose2.main import PluggableTestProgram
if __name__ == '__main__':
# Run tests with custom configuration
PluggableTestProgram(
argv=['prog', '-v', '--start-dir', 'tests'],
plugins=['nose2.plugins.coverage']
)
# Using parameterized tests
from nose2.tools import params
@params(1, 2, 3, 4)
def test_is_positive(num):
assert num > 0
# BDD-style testing with such
from nose2.tools import such
with such.A('math calculator') as it:
@it.has_setup
def setup():
it.calc = Calculator()
@it.should('add two numbers correctly')
def test_addition(case):
result = it.calc.add(2, 3)
case.assertEqual(result, 5)
it.createTests(globals())nose2 follows a plugin-based architecture that provides extensive customization and extension capabilities:
Core functionality for discovering, loading, and running tests with extensive customization options through command-line arguments and configuration files.
__version__: str
def discover(*args, **kwargs): ...
def main(*args, **kwargs): ...
class PluggableTestProgram:
def __init__(self, **kwargs): ...
def parseArgs(self, argv): ...
def loadPlugins(self): ...
def createTests(self): ...
def runTests(self): ...Utilities for writing parameterized tests, BDD-style specifications, and enhanced test setup/teardown functionality.
def params(*paramList): ...
def cartesian_params(*paramList): ...
def with_setup(setup): ...
def with_teardown(teardown): ...
class Scenario:
def having(self, description): ...
def should(self, desc): ...
def has_setup(self, func): ...
def has_teardown(self, func): ...Framework for creating custom plugins that extend nose2's functionality through a comprehensive hook system and event-driven architecture.
class Plugin:
def __init__(self, **kwargs): ...
def register(self): ...
def addOption(self, callback, short_opt, long_opt, help): ...
class Session:
def get(self, section): ...
def loadPlugins(self, plugins, exclude): ...
def loadConfigFiles(self, *filenames): ...System for managing test configuration through command-line arguments, configuration files, and programmatic settings.
class Config:
def as_bool(self, key, default=None): ...
def as_int(self, key, default=None): ...
def as_str(self, key, default=None): ...
def as_list(self, key, default=None): ...class PluggableTestLoader:
"""Test loader that defers all loading to plugins."""
suiteClass = unittest.TestSuite
def loadTestsFromModule(self, module): ...
def loadTestsFromNames(self, testNames, module=None): ...
def loadTestsFromName(self, name, module=None): ...
class PluggableTestResult:
"""Test result that defers to plugins."""
shouldStop: bool
failfast: bool
def startTest(self, test): ...
def stopTest(self, test): ...
def addError(self, test, err): ...
def addFailure(self, test, err): ...
def addSuccess(self, test): ...