Getting ready

Install nose by using pip:

C:>pip install nose

The source package can be downloaded and installed at https://pypi.org/project/nose/ by following these steps:

  1. Unzip the source package.
  2. cd to the new directory.

Then, enter the following command:

C:>python setup.py install

One of the strengths of nose is automatically collecting tests from the following:

  • Python source files
  • Directories and packages found in the working directory

To specify which tests to run, pass the relevant test names on the command line:

C:>nosetests only_test_this.py

The test names specified may be file or module names, and may optionally indicate the test case to run by separating the module or filename from the test case name with a colon. Filenames may be relative or absolute.

Some examples are as follows:

C:>nosetests test.module
C:>nosetests another.test:TestCase.test_method
C:>nosetests a.test:TestCase
C:>nosetests /path/to/test/file.py:test_function

You may also change the working directory, where nose looks for tests, by using the -w switch:

C:>nosetests -w /path/to/tests

Note, however, that support for multiple -w arguments is now deprecated and will be removed in a future release. However, it is possible to get the same behavior by specifying the target directories without the -w switch:

C:>nosetests /path/to/tests /another/path/to/tests

Further customization of test selection and loading is possible through the use of plugins.

The test result output is identical to that of unittest, except for the additional features, such as error classes, and plugin-supplied features such as output capture and assert introspection.

In the next section, we look at testing a class using nose.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.23.123