Skip to main content

unittest with plugins

Project description

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

Welcome to nose2

nose2’s extends unittest to make testing nicer.

nose2 vs nose

nose2 originated as the successor to nose.

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

nose2 vs pytest

pytest is an excellent test framework and we encourage users to consider it for new projects.

It has a bigger team of maintainers and a larger community of users.

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 requires Python 3.

It supports all versions currently supported by the CPython team, and also aims to support PyPy and cpython betas.

Python 2

Python 2 is no longer supported. The 0.12.x line of releases contains the last versions which supported Python 2.

Users of Python 2 should understand that Python 2 is EOL and the Python 2 support line for nose2 is similarly considered EOL.

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

Uploaded Source

Built Distribution

nose2-0.15.1-py3-none-any.whl (211.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nose2-0.15.1.tar.gz
  • Upload date:
  • Size: 169.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.1

File hashes

Hashes for nose2-0.15.1.tar.gz
Algorithm Hash digest
SHA256 36770f519df5becd3cbfe0bee4abbfbf9b9f6b4eb4e03361d282b7efcfc4f0df
MD5 2e5690056a6931efc668225c52c1f590
BLAKE2b-256 9ba6f29c21026c40476ce3994ac55e16ef60b9c1d2a88d02c3fc20b07d253dab

See more details on using hashes here.

File details

Details for the file nose2-0.15.1-py3-none-any.whl.

File metadata

  • Download URL: nose2-0.15.1-py3-none-any.whl
  • Upload date:
  • Size: 211.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.1

File hashes

Hashes for nose2-0.15.1-py3-none-any.whl
Algorithm Hash digest
SHA256 564450c0c4f1602dfe171902ceb4726cc56658af7a620ae1826f1ffc86b09a86
MD5 d3f1a016d92fead6cc7c91e6e6eab91c
BLAKE2b-256 87e66babe53a1dbfa55f6d30eb7408f4c4994658e5f27e3dbbb2b437912e5a32

See more details on using hashes here.

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