0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

OpenStackのtoxでどのようにテストが実行されるのか

Posted at

toxから実行されるunitおよびfunctionalテストがどのように実行されるのかを簡単にメモ。なおstestrには触れていない。

テストツール

toxからテストを実行するとtox.iniに定義に従いテストツールが起動される。
unitテストとfunctionalテストともに通常はstestrが利用されている。

stestr --test-path=./nova/tests/functional run {posargs}

デバッグを行う場合は異なり、stestrではなくoslo_debug_helperが利用される。

oslo_debug_helper {posargs}

oslo_debug_helper

oslo_debug_helperの実体はshellスクリプト。 https://github.com/openstack/oslotest/blob/master/tools/oslo_debug_helper

デバッグを行う際には自分であらかじめbreak pointをコードに埋め込み、toxにて-e debugオプションを指定してデバッグを開始する。https://docs.openstack.org/oslotest/latest/user/features.html

import pdb; pdb.set_trace()

tox -e debug $TEST_DIRコマンドを実行すると、oslo_debug_helperにて対象となるテストをtesttoolsから起動する($TEST_DIRxxx/testsなどを指定)。

oslo_debug_helperの中ではまず実行対象となるテスト関数をリストアップする。

${PYTHON} -m testtools.run discover -t ./ $TEST_DIR --list > $ALL_TESTS

ここで、ALL_TESTSにはTEST_DIR配下にある全てのテスト関数が書き込まれるため、特定のテスト関数のみを実行する場合はフィルタリングが行われる。

# getopts friendly way of determining if a positional arg has been passed
ARG1=${@:$OPTIND:1}
if [ "$ARG1" ]; then
    grep "$ARG1" < $ALL_TESTS > $TESTS_TO_RUN
else
    mv $ALL_TESTS $TESTS_TO_RUN
fi

最後にTEST_TO_RUNに書き込まれた対象のテスト関数が実行する。

${PYTHON} -m testtools.run discover --load-list $TESTS_TO_RUN
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?