Skip to main content

unittest2 with plugins, the successor to nose

Project description

pre-commit.ci status build status Documentation Latest PyPI version Supported Python Versions Join discuss@nose2.io

Welcome to nose2

nose2 is the successor to nose.

It’s unittest with plugins.

nose2 is a new project and does not support all of the features of nose. See differences for a thorough rundown.

nose2’s purpose is to extend unittest to make testing nicer and easier to understand.

nose2 vs pytest

nose2 may or may not be a good fit for your project.

If you are new to Python testing, we encourage you to also consider pytest, a popular testing framework.

Quickstart

Because nose2 is based on unittest, you can start from the Python Standard Library’s documentation for unittest and then use nose2 to add value on top of that.

nose2 looks for tests in Python files whose names start with test and runs every test function it discovers.

Here’s an example of a simple test, written in typical unittest style:

# in test_simple.py
import unittest

class TestStrings(unittest.TestCase):
    def test_upper(self):
        self.assertEqual("spam".upper(), "SPAM")

You can then run this test like so:

$ nose2 -v
test_upper (test_simple.TestStrings) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.000s

OK

However, nose2 supports more testing configuration and provides more tools than unittest on its own.

For example, this test exercises just a few of nose2’s features:

# in test_fancy.py
from nose2.tools import params

@params("Sir Bedevere", "Miss Islington", "Duck")
def test_is_knight(value):
    assert value.startswith('Sir')

and then run this like so:

$ nose2 -v --pretty-assert
test_fancy.test_is_knight:1
'Sir Bedevere' ... ok
test_fancy.test_is_knight:2
'Miss Islington' ... FAIL
test_fancy.test_is_knight:3
'Duck' ... FAIL

======================================================================
FAIL: test_fancy.test_is_knight:2
'Miss Islington'
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/mnt/ebs/home/sirosen/tmp/test_fancy.py", line 6, in test_is_knight
    assert value.startswith('Sir')
AssertionError

>>> assert value.startswith('Sir')

values:
    value = 'Miss Islington'
    value.startswith = <built-in method startswith of str object at 0x7f3c3172f430>
======================================================================
FAIL: test_fancy.test_is_knight:3
'Duck'
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/mnt/ebs/home/sirosen/tmp/test_fancy.py", line 6, in test_is_knight
    assert value.startswith('Sir')
AssertionError

>>> assert value.startswith('Sir')

values:
    value = 'Duck'
    value.startswith = <built-in method startswith of str object at 0x7f3c3172d490>
----------------------------------------------------------------------
Ran 3 tests in 0.001s

FAILED (failures=2)

Full Docs

Full documentation for nose2 is available at docs.nose2.io

Versions and Support

Changelog and Version Scheme

nose2 versions are numbered 0.MAJOR.MINOR. Minor releases contain bugfixes or smaller features. Major features or backwards incompatible changes are done in major releases.

For a full description of all past versions and changes, see the changelog.

Python Versions

nose2 supports all currently supported Python versions.

It also will continue to support Python 2 for as long as it remains feasible and a significant percentage of nose2 users are using Python 2.

Contributing

If you want to make contributions, please read the contributing guide.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nose2-0.12.0.tar.gz (177.2 kB view details)

Uploaded Source

Built Distribution

nose2-0.12.0-py2.py3-none-any.whl (152.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file nose2-0.12.0.tar.gz.

File metadata

  • Download URL: nose2-0.12.0.tar.gz
  • Upload date:
  • Size: 177.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for nose2-0.12.0.tar.gz
Algorithm Hash digest
SHA256 956e79b9bd558ee08b6200c05ad2c76465b7e3860c0c0537686089285c320113
MD5 edc78a9fb6c6881feaf2512b434a4657
BLAKE2b-256 6e0e7c8c0ddf8a8adf1f2af273a25867c6edd479ca1ee59d5fa6edc70ec249b3

See more details on using hashes here.

Provenance

File details

Details for the file nose2-0.12.0-py2.py3-none-any.whl.

File metadata

  • Download URL: nose2-0.12.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 152.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for nose2-0.12.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 da7eb5e3cbe2abb693a053e17b4fbefca98ea9ea79fc729b0b0f41e8b4196304
MD5 12e78658d4054f37940a5c41a3a4a378
BLAKE2b-256 97a8f8dc7e6ad466dff6f1bf4d7f2d804e18b8d6804ccf22095e30ac184573d9

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page