| 1 |
Differences: nose2 vs nose vs unittest2 |
| 2 |
======================================= |
| 3 |
|
| 4 |
nose2 is not nose |
| 5 |
----------------- |
| 6 |
|
| 7 |
What's Different |
| 8 |
~~~~~~~~~~~~~~~~ |
| 9 |
|
| 10 |
Python Versions |
| 11 |
^^^^^^^^^^^^^^^ |
| 12 |
|
| 13 |
nose supports Python 2.4 and above, but nose2 only supports Python versions |
| 14 |
currently supported by the Python team. |
| 15 |
|
| 16 |
Test Discovery and Loading |
| 17 |
^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 18 |
|
| 19 |
nose loads test modules lazily: tests in the first-loaded module are |
| 20 |
executed before the second module is imported. *nose2 loads all tests |
| 21 |
first, then begins test execution*. This has some important |
| 22 |
implications. |
| 23 |
|
| 24 |
First, it means that nose2 does not need a custom importer. nose2 |
| 25 |
imports test modules with :func:`__import__`. |
| 26 |
|
| 27 |
Second, it means that *nose2 does not support all of the test project |
| 28 |
layouts that nose does*. Specifically, projects that look like this |
| 29 |
will fail to load tests correctly with nose2:: |
| 30 |
|
| 31 |
. |
| 32 |
`-- tests |
| 33 |
|-- more_tests |
| 34 |
| `-- test.py |
| 35 |
`-- test.py |
| 36 |
|
| 37 |
To nose's loader, those two test modules look like different |
| 38 |
modules. But to nose2's loader, they look the same, and will not load |
| 39 |
correctly. |
| 40 |
|
| 41 |
Test Fixtures |
| 42 |
^^^^^^^^^^^^^ |
| 43 |
|
| 44 |
nose2 supports only the *same levels of fixtures as unittest2*. This |
| 45 |
means class level fixtures and module level fixtures are supported, |
| 46 |
but *package-level fixtures are not*. In addition, unlike nose, nose2 |
| 47 |
does not attempt to order tests named on the command-line to group |
| 48 |
those with the same fixtures together. |
| 49 |
|
| 50 |
|
| 51 |
Parameterized and Generator Tests |
| 52 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 53 |
|
| 54 |
nose2 supports *more kinds of parameterized and generator tests than |
| 55 |
nose*, and supports all test generators in test functions, test |
| 56 |
classes, and in unittest TestCase subclasses. nose supports them only |
| 57 |
in test functions and test classes that do not subclass |
| 58 |
unittest.TestCase. See: :doc:`plugins/generators` and |
| 59 |
:doc:`plugins/parameters` for more. |
| 60 |
|
| 61 |
Configuration |
| 62 |
^^^^^^^^^^^^^ |
| 63 |
|
| 64 |
nose expects plugins to make all of their configuration parameters |
| 65 |
available as command-line options. *nose2 expects almost all |
| 66 |
configuration to be done via configuration files*. Plugins should |
| 67 |
generally have only one command-line option: the option to activate |
| 68 |
the plugin. Other configuration parameters should be loaded from |
| 69 |
config files. This allows more repeatable test runs and keeps the set |
| 70 |
of command-line options small enough for humans to read. See: |
| 71 |
:doc:`configuration` for more. |
| 72 |
|
| 73 |
Plugin Loading |
| 74 |
^^^^^^^^^^^^^^ |
| 75 |
|
| 76 |
nose uses setuptools entry points to find and load plugins. nose2 |
| 77 |
does not. Instead, *nose2 requires that all plugins be listed in config |
| 78 |
files*. This ensures that no plugin is loaded into a test system just |
| 79 |
by virtue of being installed somewhere, and makes it easier to include |
| 80 |
plugins that are part of the project under test. See: |
| 81 |
:doc:`configuration` for more. |
| 82 |
|
| 83 |
Limited support for ``python setup.py test`` |
| 84 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 85 |
|
| 86 |
nose2 supports setuptools' ``python setup.py test`` command, but via very |
| 87 |
different means than nose. To avoid the internal complexity forced on |
| 88 |
nose by the fact that the setuptools test command can't be configured |
| 89 |
with a custom test runner, when run this way, *nose2 essentially |
| 90 |
hijacks the test running process*. The "test suite" that |
| 91 |
:func:`nose2.collector.collector` returns actually *is* a test runner, |
| 92 |
cloaked inside of a test case. It loads and runs tests as normal, |
| 93 |
setting up its own test runner and test result, and calls ``sys.exit()`` |
| 94 |
itself -- completely bypassing the test runner and test result that |
| 95 |
setuptools/unittest create. This may be incompatible with some |
| 96 |
projects. |
| 97 |
|
| 98 |
Plugin API |
| 99 |
^^^^^^^^^^ |
| 100 |
|
| 101 |
nose2 implements a new plugin API based on the work done by Michael |
| 102 |
Foord in unittest2's ``plugins`` branch. This API is greatly superior to |
| 103 |
the one in nose, especially in how it allows plugins to interact with |
| 104 |
each other. But it is different enough from the API in nose that |
| 105 |
supporting nose plugins in nose2 is not practical: *plugins must |
| 106 |
be rewritten to work with nose2*. See: :doc:`dev/writing_plugins` for more. |
| 107 |
|
| 108 |
Missing Plugins |
| 109 |
^^^^^^^^^^^^^^^ |
| 110 |
|
| 111 |
*nose2 does not include some of the more commonly-used plugins in nose*. |
| 112 |
Some of nose's builtin plugins could not be ported to nose2 due to |
| 113 |
differences in internals. See: :doc:`plugins` for information on the |
| 114 |
plugins built in to nose2. |
| 115 |
|
| 116 |
Internals |
| 117 |
^^^^^^^^^ |
| 118 |
|
| 119 |
nose wraps or replaces everything in unittest. nose2 does a bit less: |
| 120 |
*it does not wrap TestCases*, and does not wrap the test result class |
| 121 |
with a result proxy. nose2 does subclass :class:`TestProgram`, and install its |
| 122 |
own loader, runner, and result classes. It does this unconditionally, |
| 123 |
rather than allowing arguments to ``TestProgram.__init__()`` to specify |
| 124 |
the test loader and runner. See :doc:`dev/internals` for more |
| 125 |
information. |
| 126 |
|
| 127 |
License |
| 128 |
^^^^^^^ |
| 129 |
|
| 130 |
While nose was LGPL, nose2 is BSD licensed. This change was made at |
| 131 |
the request of the majority of nose contributors. |
| 132 |
|
| 133 |
What's the Same |
| 134 |
~~~~~~~~~~~~~~~ |
| 135 |
|
| 136 |
Philosophy |
| 137 |
^^^^^^^^^^ |
| 138 |
|
| 139 |
nose2 has the same goals as nose: to extend unittest to make testing |
| 140 |
nicer and easier to understand. It aims to give developers |
| 141 |
flexibility, power and transparency, so that common test scenarios |
| 142 |
require no extra work, and uncommon test scenarios can be supported |
| 143 |
with minimal fuss and magic. |
| 144 |
|
| 145 |
nose2 is not (exactly) unittest2/plugins |
| 146 |
---------------------------------------- |
| 147 |
|
| 148 |
nose2 is based on the unittest2 ``plugins`` branch, but differs from it in |
| 149 |
several substantial ways. The *event api not exactly the same* because |
| 150 |
nose2 can't replace unittest.TestCase, and *does not configure the test |
| 151 |
run or plugin set globally*. nose2 also has a *wholly different |
| 152 |
reporting API* from unittest2's plugins, to better |
| 153 |
support some common cases (like adding extra information to error |
| 154 |
output). nose2 also *defers more work to plugins* than unittest2: the |
| 155 |
test loader, runner and result are just plugin callers, and all of the |
| 156 |
logic of test discovery, running and reporting is implemented in |
| 157 |
plugins. This means that unlike unittest2, *nose2 includes a |
| 158 |
substantial set of plugins that are active by default*. |