From d802877e6e1603c4c8b73a65a38fee01dea8ee01 Mon Sep 17 00:00:00 2001 From: Eli Qiao Date: Tue, 3 Nov 2015 17:28:04 +0800 Subject: [PATCH] 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 --- test-requirements.txt | 1 + tools/flake8wrap.sh | 20 ++++++++++++++++++++ tools/pretty_tox.sh | 16 ++++++++++++++++ tox.ini | 12 ++++++++---- 4 files changed, 45 insertions(+), 4 deletions(-) create mode 100755 tools/flake8wrap.sh create mode 100755 tools/pretty_tox.sh diff --git a/test-requirements.txt b/test-requirements.txt index f0aa158eab..4b4cd564e0 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -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 diff --git a/tools/flake8wrap.sh b/tools/flake8wrap.sh new file mode 100755 index 0000000000..919ea6729c --- /dev/null +++ b/tools/flake8wrap.sh @@ -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 diff --git a/tools/pretty_tox.sh b/tools/pretty_tox.sh new file mode 100755 index 0000000000..799ac18487 --- /dev/null +++ b/tools/pretty_tox.sh @@ -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 diff --git a/tox.ini b/tox.ini index 18f265f46b..b0581918e1 100644 --- a/tox.ini +++ b/tox.ini @@ -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}