Allow running tests individually

If there is a non-zero number of arguments, run_tests.sh now
passes through the arguments to `manage.py test`, skipping the
default horizon/openstack_dashboard suites.

The correct settings module is chosen based on the first module
given in the argument. E.g., horizon.test.tests.tables chooses
the horizon.test.settings module.

Change-Id: I5321e87bec6831fb7574e045a82de06086b1d0d0
This commit is contained in:
Kieran Spear 2012-11-15 14:40:25 +11:00
parent 0e328995ec
commit 16fd3c9ebb
4 changed files with 40 additions and 4 deletions

View File

@ -43,6 +43,25 @@ tests by using the ``--skip-selenium`` flag::
This isn't recommended, but can be a timesaver when you only need to run
the code tests and not the frontend tests during development.
Running a subset of tests
-------------------------
Instead of running all tests, you can specify an individual directory, file,
class, or method that contains test code.
To run the tests in the ``horizon/test/tests/tables.py`` file::
./run_tests.sh horizon.test.tests.tables
To run the tests in the `WorkflowsTests` class in
``horizon/test/tests/workflows``::
./run_tests.sh horizon.test.tests.workflows:WorkflowsTests
To run just the `WorkflowsTests.test_workflow_view` test method::
./run_tests.sh horizon.test.tests.workflows:WorkflowsTests.test_workflow_view
Using Dashboard and Panel Templates
===================================

View File

@ -20,6 +20,8 @@ To run the tests::
$ ./run_tests.sh
It's also possible to :doc:`run a subset of unit tests<ref/run_tests>`.
.. seealso::
:doc:`ref/run_tests`

View File

@ -69,6 +69,7 @@ restore_env=0
runserver=0
only_selenium=0
with_selenium=0
testopts=""
testargs=""
with_coverage=0
makemessages=0
@ -99,17 +100,18 @@ function process_option {
--backup-environment) backup_env=1;;
--restore-environment) restore_env=1;;
--destroy-environment) destroy=1;;
-*) testopts="$testopts $1";;
*) testargs="$testargs $1"
esac
}
function run_management_command {
${command_wrapper} python $root/manage.py $testargs
${command_wrapper} python $root/manage.py $testopts $testargs
}
function run_server {
echo "Starting Django development server..."
${command_wrapper} python $root/manage.py runserver $testargs
${command_wrapper} python $root/manage.py runserver $testopts $testargs
echo "Server stopped."
}
@ -272,13 +274,26 @@ function run_tests {
export SKIP_UNITTESTS=1
fi
if [ -z "$testargs" ]; then
run_tests_all
else
run_tests_subset
fi
}
function run_tests_subset {
project=`echo $testargs | awk -F. '{print $1}'`
${command_wrapper} python $root/manage.py test --settings=$project.test.settings $testopts $testargs
}
function run_tests_all {
echo "Running Horizon application tests"
export NOSE_XUNIT_FILE=horizon/nosetests.xml
if [ "$NOSE_WITH_HTML_OUTPUT" = '1' ]; then
export NOSE_HTML_OUT_FILE='horizon_nose_results.html'
fi
${command_wrapper} coverage erase
${command_wrapper} coverage run -p $root/manage.py test horizon --settings=horizon.test.settings $testargs
${command_wrapper} coverage run -p $root/manage.py test horizon --settings=horizon.test.settings $testopts
# get results of the Horizon tests
HORIZON_RESULT=$?
@ -287,7 +302,7 @@ function run_tests {
if [ "$NOSE_WITH_HTML_OUTPUT" = '1' ]; then
export NOSE_HTML_OUT_FILE='dashboard_nose_results.html'
fi
${command_wrapper} coverage run -p $root/manage.py test openstack_dashboard --settings=openstack_dashboard.test.settings $testargs
${command_wrapper} coverage run -p $root/manage.py test openstack_dashboard --settings=openstack_dashboard.test.settings $testopts
# get results of the openstack_dashboard tests
DASHBOARD_RESULT=$?