Tempest 的执行流程
1) [user] execute “tox” command from terminal
2) [tox] load configuration from “tox.ini”, createvirtual environment and invoke testr
#tox.ini
python setup.py testr --slowest--testr-args="--subunit $TESTRARGS" | $(dirname $0)/subunit-trace.py--no-failure-debug -f
3) [testr] load configuration from “.testr.conf”, invoke testrunner “subunit.run”
#.testr.conf
[DEFAULT]
test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1}\
OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \
OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-500} \
OS_TEST_LOCK_PATH=${OS_TEST_LOCK_PATH:-${TMPDIR:-'/tmp'}} \
${PYTHON:-python} -m <em><strong><span style="color:#FF0000;">subunit.run</span></strong></em> discover -t ./${OS_TEST_PATH:-./tempest/test_discover} $LISTOPT $IDOPTION
test_id_option=--load-list$IDFILE
test_list_option=--list
group_regex=([^\.]*\.)*
4) [subunit.run] discover all the test cases (casesthat extended testtools), execute test cases
subunit.run is expected to speak subunit back to testr sothat testr can keep track of test successes and failures along with otherstatistics.
Tempest 中常用的 python package
unittest unittest2 testtools | Python unit testing framework.
Type Hierarchy: Temptest TestCase -->unittest2/testtools --> standard unittest https://blueprints.launchpad.net/tempest/+spec/speed-up-tempest |
Fixtures/ mox | Load sample data or mock data during unit testing |
subunit.run | Simple subunit testrunner for python.
|
testr/ testrepository | testr is a test runner and ispart of testrepository.
testr works by using your testrunner(in this case, subunit.run) to list all of your tests, it takes this listand partitions it into a number of partitions matching the number of CPUsavailable on the current machine, then forks that number test runners givingeach one their own partition of the test list.
The test runners (in thiscase, subunit.run) are expected to speak subunit back to testr so that testrcan keep track of test successes and failures along with other statistics.
The configuration file “.testr.conf” [DEFAULT] test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \ OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \ OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-500}\ OS_TEST_LOCK_PATH=${OS_TEST_LOCK_PATH:-${TMPDIR:-'/tmp'}} \ ${PYTHON:-python} -m subunit.run discover -t ./${OS_TEST_PATH:-./tempest/test_discover} $LISTOPT $IDOPTION test_id_option=--load-list $IDFILE test_list_option=--list group_regex=([^\.]*\.)* nosetests could do similar thing, but Tempest suggest we usetestr (http://ilearnstack.com/2013/06/02/tempest-an-openstack-integration-test-suite/) $ cd /opt/stack/tempest $ nosetests tempest/scenario/test_network_basic_ops.py $ nosetests –v tempest $ nosetests –vtempest.test.test_flavors |
tox | create a venv and run thetests. 最典型的应用就测试在不同python版本下代码的兼容性,我们可以为py2.4,py2.5,py2.6,py2.7创建不同的虚拟环境,都可以用tox统一管理;也可以在tox.ini中自定义虚拟环境,例如:testevn:pep8,代码格式检查;testenv:cover,测试覆盖率。 |