Running the Tests

Running the Tests

Mogan includes an extensive set of automated unit tests which are run through tox.

Install tox

Install tox using pip:

$ sudo pip install tox

Python Guideline Enforcement

All code has to pass the pep8 style guideline to merge into OpenStack, to validate the code against these guidelines you can run:

$ tox -e pep8

Unit Testing

It is strongly encouraged to run the unit tests locally under one or more test environments prior to submitting a patch. To run all the recommended environments sequentially and pep8 style guideline run:

$ tox

You can also selectively pick specific test environments by listing your chosen environments after a -e flag:

$ tox -e py35,py27,pep8,pypy

As tox is a wrapper around testr, it also accepts the same flags as testr. See the testr documentation for details about these additional flags.

Use a double hyphen to pass options to testr. For example, to run only tests under tests/unit/api/:

$ tox -e py27 -- mogan.tests.unit.api

Note

Tox sets up virtual environment and installs all necessary dependencies. Sharing the environment with devstack testing is not recommended due to conflicting configuration with system dependencies.

Debug tests

To debug tests (ie. break into pdb debugger), you can use ‘’debug’’ tox environment. Here’s an example, passing the name of a test since you’ll normally only want to run the test that hits your breakpoint:

$ tox -e debug mogan.tests.unit.cmd.test_dbsync.DbSyncTestCase

For reference, the debug tox environment implements the instructions here: https://wiki.openstack.org/wiki/Testr#Debugging_.28pdb.29_Tests

Functional tests

To run functional tests, you can specify the functional as test environment:

$ tox -e functional

Tempest tests

Tempest is a set of integration tests to be run against a live OpenStack environment, to run tempest of mogan part, you need to enable tempest installed and configured correctly. In devstack installation, you need to enable tempest and mogan in local.conf and run stack.sh. Then you can run mogan tempest tests with tempest run command, see:

$ ./stack.sh
$ cd /opt/stack/tempest/
$ tempest run -t --regex "^mogan\."

For more details, you can see tempest documentation

See also

Creative Commons Attribution 3.0 License

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.