OpenStack Unit Testing NuggetsSep 5, 2014
A small post about little things I found out while running unit tests in OpenStack.
./run_tests.sh is used to run the unit tests of an OpenStack
project. But, you require to install dependencies before doing it. And
installing dependencies might not always succeed. So make sure you install
these packages before running
pip install -r requirements.txt:
sudo apt-get install build-essential libssl-dev libffi-dev \ python-dev libxslt1-dev libpq-dev python-mysqldb \ libmysqlclient-dev libvirt-dev
nova dependencies will get installed properly after
run_tests frequently used commands
To force the tests to NOT run in a virtual environment, even if it is present:
Force a clean rebuild of virtual environment
Run only PEP8 checks
Run PEP8 checks only on the files which have been changed since last commit
Run all tests from a specific file only, e.g. nova/tests/test_utils.py
Run all tests of only a specific class inside a test file
Run only a specific test
Wildcards while running the tests
Frequently you’ll find yourself testing only a couple of tests. In such cases,
a wildcard will save you from typing the whole path of the test. The below
command will also run
I currently don’t know how to make a test work without adding
run_tests is not happy
Sometimes you’ll see running
./run_tests.sh can throw a lot of lines of
ununderstandable gibberish on your screen. In the end it will say
failed, but it won’t give an indication of where it failed and why. I have
seen that this happens due to only one of the following two reasons:
Syntax error: There is a syntax error in your code.
Dependencies outdated: Dependencies in your virtual environment is outdated. In such cases, you will need to recreate a virtual environment with latest packages. Or better: just update the virtual environment with the latest packages using this command:
UPDATE: I’ve seen that nowadays it doesn’t throw a lot of gibberish, but just says ‘testr failed’, without any error log or stacktrace. This is the same situation – can only happen when there is a syntax error, or if the dependencies are outdated.
That’s it for now.