Chapter 4
■
nose and nose2
84
• nose has more fixtures than unittest. In addition to the regular
unittest fixtures, nose has package- and function-level fixtures.
• nose has alternate names for fixtures.
• nose.tools offers many features for automating test cases.
• Test discovery is simpler in nose than in unittest,
as nose does
not need a Python interpreter with the discover sub-command.
• nose can recognize and run unittest tests easily.
Disadvantages of nose
The only and the biggest disadvantage of nose is that it is not under active development
and has been in maintenance mode for the past several years. It
will likely cease without
a new person or team to take over its maintenance. If you’re planning to start a project
and are looking for a suitable automation framework for Python 3, then pytest, nose2, or
plain unittest.
You might be wondering why I even spent time covering
nose if it is not being
actively developed. The reason is that learning a more advanced framework like nose
helps you understand the limitations of unittest. Also, if you are working with an older
project that uses nose as the test automation and/or
unit testing framework, it will help
you understand your tests.
Using Nose 2
nose2 is the next generation of testing for Python. It is based on the plugins branch of
unittest2.
nose2 aims to improve on nose as follows:
• It provides a better plugin API.
• It is easier for users to configure.
• It simplifies internal interfaces and processes.
• It supports Python 2 and 3 from the same codebase.
• It encourages greater community involvement in its development.
•
Unlike nose, it is under active development.
It can be installed conveniently using the following command:
sudo pip3 install nose2
Once installed, nose2 can be invoked by running nose2 at the command prompt.
It can be used to auto-discover and run the unittest and nose test modules. Run
the nose2 -h command at the command prompt to get help with the various nose2
command-line options.
Chapter 4
■
nose and nose2
85
The following are the important differences between nose and nose2:
• Python versions
nose supports Python version 2.4 and above. nose2 supports
pypy, 2.6, 2.7, 3.2, 3.3, 3.4, and 3.5. nose2 does
not support all the
versions, as it is not possible to support all the Python versions in
a single codebase.
• Test loading
nose loads and executes
test modules one by one, which is called
lazy loading. On the contrary, nose2 loads
all the modules first
and then executes them all at once.
• Test discovery
Because of the difference between the test loading techniques,
nose2 does not support all the project layouts.
The layout shown
in Figure
4-5
is supported by nose. However, it will not be loaded
correctly by nose2. nose can distinguish between ./dir1/test.
py and ./dir1/dir2/test.py.
Do'stlaringiz bilan baham: