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.13.0.tar.gz (166.9 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.13.0-py3-none-any.whl (205.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for nose2-0.13.0.tar.gz
Algorithm Hash digest
SHA256 57c68ad676ef4b88b50694937eb52f4943aa1ca261074b4909b6e163046b46f0
MD5 e5f483d17e9f42e266d8486178058c01
BLAKE2b-256 079bc2d9fc1a7e143a3f84feeff8373cecc3a0122fe2bf2486486c9557a77ba8

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for nose2-0.13.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e29017c9309fe2c8b8a1f1db7a0e7526acaba0c3990f32a0d961e6a7bc5cc190
MD5 08d4ef8410f863c14046607453db5de8
BLAKE2b-256 45959ad320e22ee0007264d0efd75a094ad93d41f3b9b65282661edb71d16019

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