| 1 |
Welcome to nose2 |
| 2 |
================ |
| 3 |
|
| 4 |
nose2's extends ``unittest`` to make testing nicer. |
| 5 |
|
| 6 |
nose2 vs nose |
| 7 |
------------- |
| 8 |
|
| 9 |
``nose2`` originated as the successor to ``nose``. |
| 10 |
|
| 11 |
``nose2`` is a distinct project and does not support all of the behaviors of ``nose``. |
| 12 |
See `differences`_ for a thorough rundown. |
| 13 |
|
| 14 |
nose2 vs pytest |
| 15 |
--------------- |
| 16 |
|
| 17 |
`pytest`_ is an excellent test framework and we encourage users to consider |
| 18 |
it for new projects. |
| 19 |
|
| 20 |
It has a bigger team of maintainers and a larger community of users. |
| 21 |
|
| 22 |
Quickstart |
| 23 |
---------- |
| 24 |
|
| 25 |
Because ``nose2`` is based on unittest, you can start from the Python Standard |
| 26 |
Library's `documentation for unittest <https://docs.python.org/library/unittest.html>`_ |
| 27 |
and then use nose2 to add value on top of that. |
| 28 |
|
| 29 |
``nose2`` looks for tests in Python files whose names start with ``test`` and |
| 30 |
runs every test function it discovers. |
| 31 |
|
| 32 |
Here's an example of a simple test, written in typical unittest style: |
| 33 |
|
| 34 |
.. code-block:: python |
| 35 |
|
| 36 |
# in test_simple.py |
| 37 |
import unittest |
| 38 |
|
| 39 |
class TestStrings(unittest.TestCase): |
| 40 |
def test_upper(self): |
| 41 |
self.assertEqual("spam".upper(), "SPAM") |
| 42 |
|
| 43 |
You can then run this test like so:: |
| 44 |
|
| 45 |
$ nose2 -v |
| 46 |
test_upper (test_simple.TestStrings) ... ok |
| 47 |
|
| 48 |
---------------------------------------------------------------------- |
| 49 |
Ran 1 test in 0.000s |
| 50 |
|
| 51 |
OK |
| 52 |
|
| 53 |
However, ``nose2`` supports more testing configuration and provides more tools |
| 54 |
than ``unittest`` on its own. |
| 55 |
|
| 56 |
For example, this test exercises just a few of ``nose2``'s features: |
| 57 |
|
| 58 |
.. code-block:: python |
| 59 |
|
| 60 |
# in test_fancy.py |
| 61 |
from nose2.tools import params |
| 62 |
|
| 63 |
@params("Sir Bedevere", "Miss Islington", "Duck") |
| 64 |
def test_is_knight(value): |
| 65 |
assert value.startswith('Sir') |
| 66 |
|
| 67 |
and then run this like so:: |
| 68 |
|
| 69 |
$ nose2 -v --pretty-assert |
| 70 |
test_fancy.test_is_knight:1 |
| 71 |
'Sir Bedevere' ... ok |
| 72 |
test_fancy.test_is_knight:2 |
| 73 |
'Miss Islington' ... FAIL |
| 74 |
test_fancy.test_is_knight:3 |
| 75 |
'Duck' ... FAIL |
| 76 |
|
| 77 |
====================================================================== |
| 78 |
FAIL: test_fancy.test_is_knight:2 |
| 79 |
'Miss Islington' |
| 80 |
---------------------------------------------------------------------- |
| 81 |
Traceback (most recent call last): |
| 82 |
File "/mnt/ebs/home/sirosen/tmp/test_fancy.py", line 6, in test_is_knight |
| 83 |
assert value.startswith('Sir') |
| 84 |
AssertionError |
| 85 |
|
| 86 |
>>> assert value.startswith('Sir') |
| 87 |
|
| 88 |
values: |
| 89 |
value = 'Miss Islington' |
| 90 |
value.startswith = <built-in method startswith of str object at 0x7f3c3172f430> |
| 91 |
====================================================================== |
| 92 |
FAIL: test_fancy.test_is_knight:3 |
| 93 |
'Duck' |
| 94 |
---------------------------------------------------------------------- |
| 95 |
Traceback (most recent call last): |
| 96 |
File "/mnt/ebs/home/sirosen/tmp/test_fancy.py", line 6, in test_is_knight |
| 97 |
assert value.startswith('Sir') |
| 98 |
AssertionError |
| 99 |
|
| 100 |
>>> assert value.startswith('Sir') |
| 101 |
|
| 102 |
values: |
| 103 |
value = 'Duck' |
| 104 |
value.startswith = <built-in method startswith of str object at 0x7f3c3172d490> |
| 105 |
---------------------------------------------------------------------- |
| 106 |
Ran 3 tests in 0.001s |
| 107 |
|
| 108 |
FAILED (failures=2) |
| 109 |
|
| 110 |
Full Docs |
| 111 |
--------- |
| 112 |
|
| 113 |
Full documentation for ``nose2`` is available at `docs.nose2.io`_ |
| 114 |
|
| 115 |
Versions and Support |
| 116 |
-------------------- |
| 117 |
|
| 118 |
Changelog and Version Scheme |
| 119 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 120 |
|
| 121 |
nose2 versions are numbered ``0.MAJOR.MINOR``. Minor releases contain bugfixes or |
| 122 |
smaller features. Major features or backwards incompatible changes are done in |
| 123 |
major releases. |
| 124 |
|
| 125 |
For a full description of all past versions and changes, see the `changelog`_. |
| 126 |
|
| 127 |
Python Versions |
| 128 |
~~~~~~~~~~~~~~~ |
| 129 |
|
| 130 |
nose2 requires Python 3. |
| 131 |
|
| 132 |
It supports all versions currently supported by the CPython team, and also aims |
| 133 |
to support PyPy and cpython betas. |
| 134 |
|
| 135 |
Python 2 |
| 136 |
******** |
| 137 |
|
| 138 |
Python 2 is no longer supported. The `0.12.x line of releases <py2line>`_ |
| 139 |
contains the last versions which supported Python 2. |
| 140 |
|
| 141 |
Users of Python 2 should understand that Python 2 is EOL and the Python 2 |
| 142 |
support line for ``nose2`` is similarly considered EOL. |
| 143 |
|
| 144 |
.. note:: |
| 145 |
|
| 146 |
Fixes to 0.12.x may still be accepted on an as-needed basis for a short |
| 147 |
while as the python3-only line of releases gets started. |
| 148 |
|
| 149 |
Contributing |
| 150 |
------------ |
| 151 |
|
| 152 |
If you want to make contributions, please read the `contributing`_ guide. |
| 153 |
|
| 154 |
.. _py2line: https://github.com/nose-devs/nose2/tree/0.12.x-line |
| 155 |
|
| 156 |
.. _differences: https://docs.nose2.io/en/latest/differences.html |
| 157 |
|
| 158 |
.. _changelog: https://docs.nose2.io/en/latest/changelog.html |
| 159 |
|
| 160 |
.. _pytest: http://pytest.readthedocs.io/en/latest/ |
| 161 |
|
| 162 |
.. _contributing: https://github.com/nose-devs/nose2/blob/main/contributing.rst |
| 163 |
|
| 164 |
.. _docs.nose2.io: https://docs.nose2.io/en/latest/ |