From 2dc6348c90f3dcf92e1e31e90b23d5fd593da6b0 Mon Sep 17 00:00:00 2001 From: gordon chung Date: Wed, 30 Jul 2014 12:02:17 -0400 Subject: [PATCH] Debug env for tox Running a test with pdb was difficult because tox captures output and causes pdb prompt to quit. Tips for how to run with debug are provided here: https://wiki.openstack.org/wiki/Testr#Debugging_.28pdb.29_Tests This change puts these commands into a debug env in tox.ini so you can do a command like: tox -e debug pycadf.tests.test_cadf_spec and when it hits your breakpoint you'll get the debug prompt. Change-Id: Ic53a888e4e305d51159d1d6a2f962786a532e089 Co-Authored-By: Brant Knudson Closes-Bug: #1350424 --- doc/source/contributing/source.rst | 10 ++++++---- tools/debug_helper.sh | 17 +++++++++++++++++ tox.ini | 4 ++++ 3 files changed, 27 insertions(+), 4 deletions(-) create mode 100755 tools/debug_helper.sh diff --git a/doc/source/contributing/source.rst b/doc/source/contributing/source.rst index e3c00874..123e4c7b 100644 --- a/doc/source/contributing/source.rst +++ b/doc/source/contributing/source.rst @@ -68,12 +68,14 @@ run through tox_. $ tox -e py27 -- api.v2 - To debug tests (ie. break into pdb debugger), you can use ''venv'' command:: + To debug tests (ie. break into pdb debugger), you can use ''debug'' tox + environment. Here's an example, passing the name of a test since you'll + normally only want to run the test that hits your breakpoint:: - $ tox -e venv "python -m unittest discover ceilometer" + $ tox -e debug ceilometer.tests.test_bin - Unfortunately, debugging currently has some limitations: - You cannot run a specific test, you have to launch the whole test suite. + For reference, the ``debug`` tox environment implements the instructions + here: https://wiki.openstack.org/wiki/Testr#Debugging_.28pdb.29_Tests .. seealso:: diff --git a/tools/debug_helper.sh b/tools/debug_helper.sh new file mode 100755 index 00000000..195aff9e --- /dev/null +++ b/tools/debug_helper.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +TMP_DIR=`mktemp -d` || exit 1 +trap "rm -rf $TMP_DIR" EXIT + +ALL_TESTS=$TMP_DIR/all_tests +TESTS_TO_RUN=$TMP_DIR/ks_to_run + +python -m testtools.run discover -t ./ ./ceilometer/tests --list > $ALL_TESTS + +if [ "$1" ]; then + grep "$1" < $ALL_TESTS > $TESTS_TO_RUN +else + mv $ALL_TESTS $TESTS_TO_RUN +fi + +STANDARD_THREADS=1 python -m testtools.run discover --load-list $TESTS_TO_RUN diff --git a/tox.ini b/tox.ini index 3f585a8b..aa0f0a14 100644 --- a/tox.ini +++ b/tox.ini @@ -44,6 +44,10 @@ commands = python setup.py build_sphinx [testenv:venv] commands = {posargs} +[testenv:debug] +commands = + bash -x {toxinidir}/setup-test-env.sh {toxinidir}/tools/debug_helper.sh {posargs} + [flake8] # H305 imports not grouped correctly ignore = H305