Add an extra parameter for test directory in debugger script
The `python-*client`'s usually give back the full package name i.e. python-keystoneclient, and the script assumes thats where the tests are, but most clients have their tests under just *client, or in this case keystoneclient. Oslo projects have a similar issue. Change the debug script to accept an optional argument that can be used to override the guesstimated value. Change-Id: If0a25ae7ab9f854f87271a377dd228e2ebfb107f
This commit is contained in:
parent
c8bbab8ee6
commit
e5c14b74d3
|
@ -25,7 +25,22 @@ Update tox.ini
|
||||||
Within the ``tox.ini`` file of your project add the following::
|
Within the ``tox.ini`` file of your project add the following::
|
||||||
|
|
||||||
[testenv:debug]
|
[testenv:debug]
|
||||||
commands = oslo_debug_helper.sh {posargs}
|
commands = oslo_debug_helper {posargs}
|
||||||
|
|
||||||
|
If the project name, and the module that precedes the tests directory do not
|
||||||
|
match, then consider passing an argument to ``tox.ini``.
|
||||||
|
|
||||||
|
For example, ``python-keystoneclient`` project has tests in
|
||||||
|
``keystoneclient/tests``, thus it would have to pass in::
|
||||||
|
|
||||||
|
[testenv:debug]
|
||||||
|
commands = oslo_debug_helper -t keystoneclient/tests {posargs}
|
||||||
|
|
||||||
|
Similarily, most ``oslo`` projects have the tests at the package level, it
|
||||||
|
would have to pass in::
|
||||||
|
|
||||||
|
[testenv:debug]
|
||||||
|
commands = oslo_debug_helper -t tests {posargs}
|
||||||
|
|
||||||
To run with tox:
|
To run with tox:
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,40 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# oslo_debug_helper - Script that allows for debugging tests
|
||||||
|
#
|
||||||
|
# oslo_debug_helper [-t <test_directory>] [<tests_to_run>]
|
||||||
|
#
|
||||||
|
# <tests_to_run> - may be a test suite, class, or function, if no value is
|
||||||
|
# passed, then all tests are run.
|
||||||
|
# -t <test_directory> - the name of the directory that houses the tests
|
||||||
|
# relative to the project directory. If no value is passed, it is assumed
|
||||||
|
# to be packagename/tests.
|
||||||
|
|
||||||
TMP_DIR=`mktemp -d` || exit 1
|
TMP_DIR=`mktemp -d` || exit 1
|
||||||
trap "rm -rf $TMP_DIR" EXIT
|
trap "rm -rf $TMP_DIR" EXIT
|
||||||
|
|
||||||
ALL_TESTS=$TMP_DIR/all_tests
|
ALL_TESTS=$TMP_DIR/all_tests
|
||||||
TESTS_TO_RUN=$TMP_DIR/tests_to_run
|
TESTS_TO_RUN=$TMP_DIR/tests_to_run
|
||||||
|
|
||||||
|
# Default to packagename/tests, i.e., keystone/tests
|
||||||
PACKAGENAME=$(python setup.py --name)
|
PACKAGENAME=$(python setup.py --name)
|
||||||
|
TEST_DIR=./$PACKAGENAME/tests
|
||||||
|
|
||||||
python -m testtools.run discover -t ./ ./$PACKAGENAME/tests --list > $ALL_TESTS
|
# If a specific path is passed, use that one
|
||||||
|
while getopts ":t:" opt; do
|
||||||
|
case $opt in
|
||||||
|
t) TEST_DIR=$OPTARG;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
if [ "$1" ]; then
|
python -m testtools.run discover -t ./ $TEST_DIR --list > $ALL_TESTS
|
||||||
grep "$1" < $ALL_TESTS > $TESTS_TO_RUN
|
|
||||||
|
# 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
|
else
|
||||||
mv $ALL_TESTS $TESTS_TO_RUN
|
mv $ALL_TESTS $TESTS_TO_RUN
|
||||||
fi
|
fi
|
||||||
|
|
||||||
python -m testtools.run discover --load-list $TESTS_TO_RUN
|
python -m testtools.run discover --load-list $TESTS_TO_RUN
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue