loading...

Get your nose in your python (starting with `nose2`)

malikbenkirane profile image Malik Benkirane ・2 min read

I need to build some tests with python. This can usually be done coding a
module with many asserts or doing everything manually aka typing some


python -i totest.py

then playing around with the code to see if there are case where the code is
broken. But you would agree that it's better to design well the tests for your
code in order to automate this process for example. This process has already
been discussed since very long time ago and there is very few things left
behind this. Moreover, this process has also been extended to things so called
continuous integration, code coverage or you may have heard of builds that
pass. That's right, you can always put tests in the build process. Pythonistas
could rather use nose2.

Installation

You could use any environment (virtual, user, global) to install nose2


pip[3] install [--user] --upgrade nose2

For Python 2.7 and pypy, nose2 requires six version 1.1.

How this works ?

To find tests, nose2 looks for modules whose names start with test. In
those modules, nose2 will load tests from all unittest.TestCase
subclasses, as well as functions whose names start with test.

Basically you need to write the python tests and execute nose2 to take care
of your testing jobs. And

nose2 will look in each directory under the starting directory, unless the
configuration modifies the included paths. Within directories and within any
Python packages found in the starting directory and any source directories in
the starting directory, nose2 will discover test modules and load tests from
them.

just


nose2

great right ?

Naming Tests

nose2 looks in

  • directories that contains __init__.py
  • direcotries that the lowercased name contains test
  • directories the name is either src or lib

and (without configuration)

  • nose2 will run all python files (.py extension) that the name starts with test
  • within test modules, nose2 loads unittest.TestCase subclasses

What's next ?

Greetings,

Discussion

markdown guide