Skip to content

Commit

Permalink
Allow running tests individually
Browse files Browse the repository at this point in the history
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
  • Loading branch information
spearki committed Nov 15, 2012
1 parent 0e32899 commit 16fd3c9
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
19 changes: 19 additions & 0 deletions doc/source/ref/run_tests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
===================================

Expand Down
2 changes: 2 additions & 0 deletions doc/source/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ before you submit any pull requests/patches.
To run the tests::

$ ./run_tests.sh
It's also possible to :doc:`run a subset of unit tests<ref/run_tests>`.

.. seealso::

Expand Down
Empty file.
23 changes: 19 additions & 4 deletions run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ restore_env=0
runserver=0
only_selenium=0
with_selenium=0
testopts=""
testargs=""
with_coverage=0
makemessages=0
Expand Down Expand Up @@ -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."
}

Expand Down Expand Up @@ -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=$?

Expand All @@ -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=$?

Expand Down

0 comments on commit 16fd3c9

Please sign in to comment.