James E. Blair | 9ab8662 | 2013-07-02 11:23:46 -0700 | [diff] [blame] | 1 | =========================== |
| 2 | Testing Your OpenStack Code |
| 3 | =========================== |
| 4 | ------------ |
| 5 | A Quickstart |
| 6 | ------------ |
| 7 | |
| 8 | This is designed to be enough information for you to run your first tests. |
| 9 | Detailed information on testing can be found here: https://wiki.openstack.org/wiki/Testing |
| 10 | |
| 11 | *Install pip*:: |
| 12 | |
| 13 | [apt-get | yum] install python-pip |
Monty Taylor | 4a781a7 | 2017-07-25 07:28:04 -0400 | [diff] [blame] | 14 | |
James E. Blair | 9ab8662 | 2013-07-02 11:23:46 -0700 | [diff] [blame] | 15 | More information on pip here: http://www.pip-installer.org/en/latest/ |
| 16 | |
| 17 | *Use pip to install tox*:: |
| 18 | |
| 19 | pip install tox |
| 20 | |
Jesse Keating | da81953 | 2017-03-01 13:17:59 -0800 | [diff] [blame] | 21 | As of zuul v3, a running zookeeper is required to execute tests. |
| 22 | |
| 23 | *Install zookeeper*:: |
| 24 | |
| 25 | [apt-get | yum] install zookeeperd |
| 26 | |
| 27 | *Start zookeeper*:: |
| 28 | |
| 29 | service zookeeper start |
| 30 | |
Monty Taylor | 4a781a7 | 2017-07-25 07:28:04 -0400 | [diff] [blame] | 31 | .. note:: Installing and bulding javascript is not required, but tests that |
| 32 | depend on the javascript assets having been built will be skipped |
| 33 | if you don't. |
| 34 | |
| 35 | *Install javascript tools*:: |
| 36 | |
| 37 | tools/install-js-tools.sh |
| 38 | |
| 39 | *Install javascript dependencies*:: |
| 40 | |
| 41 | yarn install |
| 42 | |
| 43 | *Build javascript assets*:: |
| 44 | |
| 45 | npm run build:dev |
| 46 | |
James E. Blair | 9ab8662 | 2013-07-02 11:23:46 -0700 | [diff] [blame] | 47 | Run The Tests |
| 48 | ------------- |
| 49 | |
| 50 | *Navigate to the project's root directory and execute*:: |
| 51 | |
| 52 | tox |
| 53 | Note: completing this command may take a long time (depends on system resources) |
| 54 | also, you might not see any output until tox is complete. |
| 55 | |
| 56 | Information about tox can be found here: http://testrun.org/tox/latest/ |
| 57 | |
| 58 | |
| 59 | Run The Tests in One Environment |
| 60 | -------------------------------- |
| 61 | |
| 62 | Tox will run your entire test suite in the environments specified in the project tox.ini:: |
| 63 | |
| 64 | [tox] |
| 65 | |
| 66 | envlist = <list of available environments> |
| 67 | |
| 68 | To run the test suite in just one of the environments in envlist execute:: |
| 69 | |
| 70 | tox -e <env> |
| 71 | so for example, *run the test suite in py26*:: |
| 72 | |
| 73 | tox -e py26 |
| 74 | |
| 75 | Run One Test |
| 76 | ------------ |
| 77 | |
| 78 | To run individual tests with tox:: |
| 79 | |
| 80 | tox -e <env> -- path.to.module.Class.test |
| 81 | |
| 82 | For example, to *run the basic Zuul test*:: |
| 83 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 84 | tox -e py27 -- tests.unit.test_scheduler.TestScheduler.test_jobs_executed |
James E. Blair | 9ab8662 | 2013-07-02 11:23:46 -0700 | [diff] [blame] | 85 | |
| 86 | To *run one test in the foreground* (after previously having run tox |
| 87 | to set up the virtualenv):: |
| 88 | |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame] | 89 | .tox/py27/bin/python -m testtools.run tests.unit.test_scheduler.TestScheduler.test_jobs_executed |
James E. Blair | 9ab8662 | 2013-07-02 11:23:46 -0700 | [diff] [blame] | 90 | |
James E. Blair | dda6c91 | 2013-07-29 14:12:12 -0700 | [diff] [blame] | 91 | List Failing Tests |
| 92 | ------------------ |
| 93 | |
| 94 | .tox/py27/bin/activate |
| 95 | testr failing --list |
| 96 | |
James E. Blair | 6c358e7 | 2013-07-29 17:06:47 -0700 | [diff] [blame] | 97 | Hanging Tests |
| 98 | ------------- |
| 99 | |
| 100 | The following will run each test in turn and print the name of the |
| 101 | test as it is run:: |
| 102 | |
| 103 | . .tox/py27/bin/activate |
| 104 | testr run --subunit | subunit2pyunit |
| 105 | |
| 106 | You can compare the output of that to:: |
| 107 | |
| 108 | python -m testtools.run discover --list |
| 109 | |
James E. Blair | 9ab8662 | 2013-07-02 11:23:46 -0700 | [diff] [blame] | 110 | Need More Info? |
| 111 | --------------- |
| 112 | |
| 113 | More information about testr: https://wiki.openstack.org/wiki/Testr |
| 114 | |
| 115 | More information about nose: https://nose.readthedocs.org/en/latest/ |
| 116 | |
| 117 | |
| 118 | More information about testing OpenStack code can be found here: |
| 119 | https://wiki.openstack.org/wiki/Testing |