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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nose2-0.16.0-py3-none-any.whl (213.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nose2-0.16.0.tar.gz
  • Upload date:
  • Size: 172.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for nose2-0.16.0.tar.gz
Algorithm Hash digest
SHA256 19db5ad20e264501a8ee64e3e157a3766a5e744170e54ceecb4e5ca09b08655a
MD5 e5a064122904db4797e26540d89554f4
BLAKE2b-256 51b273553c0e19c4bfe174940de03c2e1814f407e3524628690800f2536bf7f7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nose2-0.16.0-py3-none-any.whl
  • Upload date:
  • Size: 213.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for nose2-0.16.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a637c508b1fff5882c5f0f573226abe6f43b2f8005fef8896f57174d7d0e0c31
MD5 b1601b81a9df38097ef5c73b55db2b0c
BLAKE2b-256 603be93d177001ac3ba3cb2ebed7727442e1ee61990271f2bf39caef63798ead

See more details on using hashes here.

Supported by

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