Skip to main content

unittest2 with plugins, the succesor 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 python2 for as long as it remains feasible and a significant percentage of nose2 users are using python2.

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.11.0.tar.gz (167.3 kB view details)

Uploaded Source

Built Distribution

nose2-0.11.0-py2.py3-none-any.whl (144.1 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: nose2-0.11.0.tar.gz
  • Upload date:
  • Size: 167.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for nose2-0.11.0.tar.gz
Algorithm Hash digest
SHA256 6d208d7d6ec9f9d55c74dac81c9394bc3906dbef81a8ca5420b2b9b7f8e69de9
MD5 1ab33117498aa06cd64699178cc11f09
BLAKE2b-256 1f24d4d16329a7c58d342a0345bbcd1dc81321fb7a1de41dc3361a48f2381e0e

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: nose2-0.11.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 144.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for nose2-0.11.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d37e75e3010bb4739fe6045a29d4c633ac3146cb5704ee4e4a9e4abeceb2dee3
MD5 78ef8eadde85ca08882f1339c00f3527
BLAKE2b-256 f55c18e2e45551825d5402012979d8ccc518f3c978bc8f194018500705d5a6ee

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