Here’s how we usually run a single test
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
| dims@dims-mac:~/openstack/nova$ time tox -e py27 nova.tests.unit.test_versions py27 develop-inst-noop: /Users/dims/openstack/nova py27 runtests: PYTHONHASHSEED='0' py27 runtests: commands[0] | find . -type f -name *.pyc -delete py27 runtests: commands[1] | bash tools/pretty_tox.sh nova.tests.unit.test_versions {1} nova.tests.unit.test_versions.VersionTestCase.test_version_string_with_package_is_good [0.180036s] ... ok {0} nova.tests.unit.test_versions.VersionTestCase.test_release_file [0.184115s] ... ok ====== Totals ====== Ran: 2 tests in 13.0000 sec. - Passed: 2 - Skipped: 0 - Failed: 0 Sum of execute time for each test: 0.3642 sec. ============== Worker Balance ============== - Worker 0 (1 tests) => 0:00:00.184115s - Worker 1 (1 tests) => 0:00:00.180036s ________________________________________________________________________________________________________________________ summary _________________________________________________________________________________________________________________________ py27: commands succeeded congratulations <span class="wp-smiley wp-emoji wp-emoji-smile" title=":)">:)</span> real 0m14.452s user 0m16.392s sys 0m2.354s |
Sometimes the usual way is not very helpful, especially when you are working on some new code and say running into issues importing code. Then, here’s what you do.
First, activate the py27 virtualenv
1
| dims@dims-mac:~/openstack/nova$ . .tox/py27/bin/activate |
Then use testtools
1
2
3
4
5
| (py27)dims@dims-mac:~/openstack/nova$ python -m testtools.run nova.tests.unit.test_versions Tests running... Ran 2 tests in 0.090s OK |
Or you can install pytest
1
2
3
4
5
6
7
8
9
10
11
12
13
| (py27)dims@dims-mac:~/openstack/nova$ pip install pytest Collecting pytest Downloading pytest-2.6.4.tar.gz (512kB) 100% |################################| 516kB 877kB/s Collecting py>=1.4.25 (from pytest) Downloading py-1.4.26.tar.gz (190kB) 100% |################################| 192kB 4.3MB/s Installing collected packages: py, pytest Running setup.py install for py Running setup.py install for pytest Installing py.test-2.7 script to /Users/dims/openstack/nova/.tox/py27/bin Installing py.test script to /Users/dims/openstack/nova/.tox/py27/bin Successfully installed py-1.4.26 pytest-2.6.4 |
And then run the same test using py.test
1
2
3
4
5
6
7
8
9
10
11
12
| (py27)dims@dims-mac:~/openstack/nova$ find . -name py.test ./.tox/py27/bin/py.test (py27)dims@dims-mac:~/openstack/nova$ .tox/py27/bin/py.test -svx nova/tests/unit/test_versions.py ================================================================================================================== test session starts =================================================================================================================== platform darwin -- Python 2.7.8 -- py-1.4.26 -- pytest-2.6.4 -- /Users/dims/openstack/nova/.tox/py27/bin/python2.7 collected 2 items nova/tests/unit/test_versions.py::VersionTestCase::test_release_file PASSED nova/tests/unit/test_versions.py::VersionTestCase::test_version_string_with_package_is_good PASSED ================================================================================================================ 2 passed in 1.69 seconds ================================================================================================================ |
These tips are based on the openstack-dev mailing list discussion:
http://openstack.markmail.org/thread/wetxcnhuq6b7auhn
http://openstack.markmail.org/thread/wetxcnhuq6b7auhn
No comments:
Post a Comment