From 55f23369819de8821c69c0b45ac9a05c6a833798 Mon Sep 17 00:00:00 2001 From: Doug Wiegley Date: Tue, 19 Feb 2019 14:07:03 -0700 Subject: [PATCH] Add method to tox to use local neutron-lib with unit tests Change-Id: Ic96bb04cc3f9ed1438596b2150030ab22887b091 --- TESTING.rst | 35 ++++++++++++++++++++++++++++++++ tools/pip_install_src_modules.sh | 25 +++++++++++++++++++++++ tox.ini | 7 +++++-- 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100755 tools/pip_install_src_modules.sh diff --git a/TESTING.rst b/TESTING.rst index 63e352b5497..9220992b5aa 100644 --- a/TESTING.rst +++ b/TESTING.rst @@ -509,6 +509,41 @@ To run only the unit tests:: tox -e py27 +Many changes span across both the neutron and neutron-lib repos, and tox +will always build the test environment using the published module versions +specified in requirements.txt and lower-constraints.txt. To run tox tests +against a different version of neutron-lib, use the TOX_ENV_SRC_MODULES +environment variable to point at a local package repo. + +For example, to run against the 'master' branch of neutron-lib: + + cd $SRC + git clone git://git.openstack.org/openstack/neutron-lib + cd $NEUTRON_DIR + env TOX_ENV_SRC_MODULES=$SRC/neutron-lib tox -r -e pep8,py27 + +To run against a change of your own, repeat the same steps, but use the +directory with your changes, not a fresh clone. + +To run against a particular gerrit change of the lib (substituting the +desired gerrit refs for this example): + + cd $SRC + git clone git://git.openstack.org/openstack/neutron-lib + cd neutron-lib + git fetch git://git.openstack.org/openstack/neutron-lib refs/changes/13/635313/6 && git checkout FETCH_HEAD + cd $NEUTRON_DIR + env TOX_ENV_SRC_MODULES=$SRC/neutron-lib tox -r -e pep8,py27 + +Note that the '-r' is needed to re-create the tox virtual envs, and will also +be needed to restore them to standard when not using this method. + +Any pip installable package can be overriden with this environment variable, +not just neutron-lib. To specify multiple packages to override, specify them +as a space separated list to TOX_ENV_SRC_MODULES. Example: + + env TOX_ENV_SRC_MODULES="$SRC/neutron-lib $SRC/oslo.db" tox -r -e pep8,py27 + Functional Tests ~~~~~~~~~~~~~~~~ diff --git a/tools/pip_install_src_modules.sh b/tools/pip_install_src_modules.sh new file mode 100755 index 00000000000..280b4d85e50 --- /dev/null +++ b/tools/pip_install_src_modules.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# For neutron unit tests, you can define git repos containing modules +# that you want to use to override the requirements-based packages. +# +# Why, you ask? Because you made changes to neutron-lib, and you want +# run the unit tests together. E.g.: +# +# env TOX_ENV_SRC_MODULES="$HOME/src/neutron-lib" tox -e py27 + +toxinidir="$1" + +if [ -z "$TOX_ENV_SRC_MODULES" ]; then + exit 0 +fi + +for repo in $TOX_ENV_SRC_MODULES; do + d="${toxinidir}/${repo}" + if [ ! -d "$d" ]; then + echo "tox_env_src: error: no directory found at $d" + continue + fi + echo "tox_env_src: pip installing from $d" + pip install -e "$d" +done diff --git a/tox.ini b/tox.ini index d08f380c232..d210fcfb17a 100644 --- a/tox.ini +++ b/tox.ini @@ -9,7 +9,7 @@ setenv = VIRTUAL_ENV={envdir} OS_STDOUT_CAPTURE={env:OS_STDOUT_CAPTURE:true} OS_STDERR_CAPTURE={env:OS_STDERR_CAPTURE:true} PYTHONWARNINGS=default::DeprecationWarning,ignore::DeprecationWarning:distutils,ignore::DeprecationWarning:site -passenv = TRACE_FAILONLY GENERATE_HASHES http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy NO_PROXY +passenv = TRACE_FAILONLY GENERATE_HASHES http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy NO_PROXY TOX_ENV_SRC_MODULES usedevelop = True install_command = pip install {opts} {packages} @@ -18,7 +18,10 @@ deps = -r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt whitelist_externals = sh -commands = stestr run {posargs} +commands = + {toxinidir}/tools/pip_install_src_modules.sh "{toxinidir}" + stestr run {posargs} + # there is also secret magic in ostestr which lets you run in a fail only # mode. To do this define the TRACE_FAILONLY environmental variable.