or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

configuration.mdindex.mdplugin-development.mdtest-discovery.mdtest-tools.md
tile.json

tessl/pypi-nose2

A testing framework that extends unittest with plugins and enhanced discovery capabilities

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/nose2@0.15.x

To install, run

npx @tessl/cli install tessl/pypi-nose2@0.15.0

index.mddocs/

nose2

A 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.

Package Information

  • Package Name: nose2
  • Language: Python
  • Installation: pip install nose2

Core Imports

import nose2

Test runner imports:

from nose2 import main, discover

Testing tools and utilities:

from nose2.tools import params, cartesian_params, such
from nose2.tools.decorators import with_setup, with_teardown

Plugin development:

from nose2.events import Plugin
from nose2.session import Session

Basic Usage

# 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())

Architecture

nose2 follows a plugin-based architecture that provides extensive customization and extension capabilities:

  • Session: Central configuration manager that handles command-line arguments, config files, and plugin lifecycle
  • PluggableTestProgram: Main test runner that coordinates discovery, loading, and execution through plugins
  • Plugin System: Hook-based architecture allowing plugins to modify behavior at every stage of test execution
  • Event-driven: All plugin interactions happen through well-defined events and hooks
  • Loaders: Pluggable test discovery and loading system supporting various test types and patterns

Capabilities

Test Discovery and Execution

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): ...

Test Discovery and Execution

Test Tools and Decorators

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): ...

Test Tools and Decorators

Plugin Development

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): ...

Plugin Development

Configuration Management

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): ...

Configuration Management

Types

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): ...