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,测试覆盖率。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值