Improve tox.ini to easy developer's life

This patch is mainly porting from nova repository:

Adds:
1.tools/flake8wrap.sh
  Will let developer use 'tox -epep8 -- -HEAD' to testing changes files
2.tools/pretty_tox.sh
  Give pretty test trace when doing unit/functional testing.

Change-Id: Icedb4ed8b50532531e18784a1584fe63c5a9e017
This commit is contained in:
Eli Qiao 2015-11-03 17:28:04 +08:00
parent 798c7e35ef
commit d802877e6e
4 changed files with 45 additions and 4 deletions

View File

@ -12,6 +12,7 @@ hacking<0.11,>=0.10.0 # Apache-2.0
mock>=1.2
oslosphinx>=2.5.0 # Apache-2.0
oslotest>=1.10.0 # Apache-2.0
os-testr>=0.4.1
python-subunit>=0.0.18
sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2
testrepository>=0.0.18

20
tools/flake8wrap.sh Executable file
View File

@ -0,0 +1,20 @@
#!/bin/sh
#
# A simple wrapper around flake8 which makes it possible
# to ask it to only verify files changed in the current
# git HEAD patch.
#
# Intended to be invoked via tox:
#
# tox -epep8 -- -HEAD
#
if test "x$1" = "x-HEAD" ; then
shift
files=$(git diff --name-only HEAD~1 | tr '\n' ' ')
echo "Running flake8 on ${files}"
diff -u --from-file /dev/null ${files} | flake8 --max-complexity 10 --diff "$@"
else
echo "Running flake8 on all files"
exec flake8 --max-complexity 10 "$@"
fi

16
tools/pretty_tox.sh Executable file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -o pipefail
TESTRARGS=$1
# --until-failure is not compatible with --subunit see:
#
# https://bugs.launchpad.net/testrepository/+bug/1411804
#
# this work around exists until that is addressed
if [[ "$TESTARGS" =~ "until-failure" ]]; then
python setup.py testr --slowest --testr-args="$TESTRARGS"
else
python setup.py testr --slowest --testr-args="--subunit $TESTRARGS" | subunit-trace -f
fi

12
tox.ini
View File

@ -6,15 +6,16 @@ skipsdist = True
[testenv]
usedevelop = True
install_command = pip install -U {opts} {packages}
whitelist_externals = find
whitelist_externals = bash
find
setenv =
VIRTUAL_ENV={envdir}
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
passenv = http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy NO_PROXY
commands =
find . -type f -name "*.pyc" -delete
python setup.py testr --slowest --testr-args='{posargs}'
passenv = http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy NO_PROXY
bash tools/pretty_tox.sh '{posargs}'
[testenv:functional]
sitepackages = True
@ -22,11 +23,14 @@ setenv = OS_TEST_PATH=./magnum/tests/functional
OS_TEST_TIMEOUT=7200
deps =
{[testenv]deps}
commands =
find . -type f -name "*.pyc" -delete
bash tools/pretty_tox.sh '{posargs}'
[testenv:pep8]
commands =
doc8 -e .rst specs/ doc/source/ contrib/ CONTRIBUTING.rst HACKING.rst README.rst
flake8 --max-complexity 10 {posargs}
bash tools/flake8wrap.sh {posargs}
[testenv:venv]
commands = {posargs}