天天看點

OpenStack / Tempest中常用的幾個Package

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.
  • unittest: Python standard library's unit testing framework.
  • unittest2: enhanced version of standard unittest. Will be used in Tempest only for python 2.6
  • testools: another extension to standard unittest. Will be used in Tempest for both python 2.6 and 2.7 and above.

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.
  • Run a unittest testcase reporting results as Subunit. $ python -m subunit.run mylib.tests.test_suite
  • subunit.runextend/wrap most functions from testtools
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,測試覆寫率。

繼續閱讀