summaryrefslogtreecommitdiff
path: root/doc/source/contributor/unit_tests.rst
blob: 07247aa3643bbf6c14138c426b6443857c24c7cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
==========
Unit Tests
==========

Cinderclient contains a suite of unit tests, in the cinderclient/tests/unit
directory.

Any proposed code change will be automatically rejected by the OpenStack
Jenkins server if the change causes unit test failures.

Running the tests
-----------------
There are a number of ways to run unit tests currently, and there's a
combination of frameworks used depending on what commands you use.  The
preferred method is to use tox, which calls ostestr via the tox.ini file.
To run all tests simply run::

    tox

This will create a virtual environment, load all the packages from
test-requirements.txt and run all unit tests as well as run flake8 and hacking
checks against the code.

Note that you can inspect the tox.ini file to get more details on the available
options and what the test run does by default.

Running a subset of tests using tox
-----------------------------------
One common activity is to just run a single test, you can do this with tox
simply by specifying to just run py27 or py35 tests against a single test::

    tox -epy27 -- -n cinderclient.tests.unit.v2.test_volumes.VolumesTest.test_attach

Or all tests in the test_volumes.py file::

    tox -epy27 -- -n cinderclient.tests.unit.v2.test_volumes

For more information on these options and how to run tests, please see the
`ostestr documentation <https://docs.openstack.org/os-testr/latest/>`_.

Gotchas
-------

**Running Tests from Shared Folders**

If you are running the unit tests from a shared folder, you may see tests start
to fail or stop completely as a result of Python lockfile issues. You
can get around this by manually setting or updating the following line in
``cinder/tests/conf_fixture.py``::

    CONF['lock_path'].SetDefault('/tmp')

Note that you may use any location (not just ``/tmp``!) as long as it is not
a shared folder.

.. rubric:: Footnotes