Skip to content
The successor to nose, based on unittest2
Python Makefile
Branch: master
Clone or download
scottgigante and sirosen Remove deprecated import of SafeConfigParser (#454)
Remove deprecated import of SafeConfigParser
Latest commit 70a7fd4 Dec 9, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs Enable multiprocess compatibility within coverage plugin Dec 8, 2019
nose2 Remove deprecated import of SafeConfigParser (#454) Dec 9, 2019
.coveragerc Move coverage config to .coveragerc Jul 22, 2013
.gitignore
.readthedocs-requirements.txt Tweak readthedocs requirements data Jan 9, 2019
.travis.yml Add testing under an sdist install Apr 2, 2019
AUTHORS Replace Gitter usage with discuss@nose2.io Mar 17, 2019
MANIFEST.in Add missing requirements files to package data Dec 13, 2017
Makefile Update setuptools & makefile to run `make release` Mar 17, 2019
README.rst Add first draft of quickstart guide Mar 31, 2019
changelog.rst release 0.6.1 Feb 26, 2016
contributing.rst Replace Gitter usage with discuss@nose2.io Mar 17, 2019
license.txt Add license file Jan 19, 2012
setup.cfg Update setuptools & makefile to run `make release` Mar 17, 2019
setup.py Drop distutils support, simplify setup.py Dec 1, 2018
tox-win32.ini Remove rundundant code for already-dropped EOL versions Nov 5, 2018
tox.ini Enable pretty-assert on nose2's own testsuite Mar 31, 2019
unit_workaround.py Drop unsupported Python 2.6 and 3.2 (#341) Oct 21, 2017
unittest.cfg Turn on log capture Jan 23, 2012

README.rst

Build Status Coverage Status 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

Contributing

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

You can’t perform that action at this time.