From 32a3244bb4879f5c0ea430de6fac284b2a987441 Mon Sep 17 00:00:00 2001
From: Vu Cong Tuan <tuanvc@vn.fujitsu.com>
Date: Thu, 12 Jul 2018 15:23:08 +0700
Subject: [PATCH] Switch to stestr

According to Openstack summit session [1],
stestr is maintained project to which all Openstack projects should migrate.
Let's switch to stestr as other projects have already moved to it.

[1] https://etherpad.openstack.org/p/YVR-python-pti

Change-Id: I55060b1d99b9a00b20c98fbb429d072568265695
---
 .gitignore            |  2 +-
 .stestr.conf          |  3 +++
 .testr.conf           |  7 -------
 lower-constraints.txt |  4 +---
 test-requirements.txt |  3 +--
 tools/pretty_tox.sh   | 16 ----------------
 tox.ini               | 22 ++++++++++------------
 7 files changed, 16 insertions(+), 41 deletions(-)
 create mode 100644 .stestr.conf
 delete mode 100644 .testr.conf
 delete mode 100755 tools/pretty_tox.sh

diff --git a/.gitignore b/.gitignore
index 82ede6ad7..611c10e37 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,6 @@
 .coverage
 .venv
-.testrepository
+.stestr/
 subunit.log
 .tox
 *,cover
diff --git a/.stestr.conf b/.stestr.conf
new file mode 100644
index 000000000..ac945e834
--- /dev/null
+++ b/.stestr.conf
@@ -0,0 +1,3 @@
+[DEFAULT]
+test_path=${OS_TEST_PATH:-./novaclient/tests/unit}
+top_dir=./
diff --git a/.testr.conf b/.testr.conf
deleted file mode 100644
index c8fae426b..000000000
--- a/.testr.conf
+++ /dev/null
@@ -1,7 +0,0 @@
-[DEFAULT]
-test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \
-             OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \
-             OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-300} \
-             ${PYTHON:-python} -m subunit.run discover -t ./ ${OS_TEST_PATH:-./novaclient/tests/unit} $LISTOPT $IDOPTION
-test_id_option=--load-list $IDFILE
-test_list_option=--list
diff --git a/lower-constraints.txt b/lower-constraints.txt
index c1cf2fc79..4f156569f 100644
--- a/lower-constraints.txt
+++ b/lower-constraints.txt
@@ -48,7 +48,6 @@ netifaces==0.10.4
 openstacksdk==0.11.2
 os-client-config==1.28.0
 os-service-types==1.2.0
-os-testr==1.0.0
 osc-lib==1.8.0
 oslo.concurrency==3.25.0
 oslo.config==5.2.0
@@ -96,11 +95,10 @@ simplejson==3.5.1
 six==1.10.0
 smmap==0.9.0
 statsd==3.2.1
-stestr==1.0.0
 stevedore==1.20.0
 tempest==17.1.0
 tenacity==3.2.1
-testrepository==0.0.18
+stestr==2.0.0
 testscenarios==0.4
 testtools==2.2.0
 traceback2==1.4.0
diff --git a/test-requirements.txt b/test-requirements.txt
index 271300b20..3c35fec9e 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -15,9 +15,8 @@ python-glanceclient>=2.8.0 # Apache-2.0
 python-neutronclient>=6.7.0 # Apache-2.0
 requests-mock>=1.2.0 # Apache-2.0
 os-client-config>=1.28.0 # Apache-2.0
-os-testr>=1.0.0 # Apache-2.0
 osprofiler>=1.4.0 # Apache-2.0
-testrepository>=0.0.18 # Apache-2.0/BSD
+stestr>=2.0.0 # Apache-2.0
 testscenarios>=0.4 # Apache-2.0/BSD
 testtools>=2.2.0 # MIT
 tempest>=17.1.0 # Apache-2.0
diff --git a/tools/pretty_tox.sh b/tools/pretty_tox.sh
deleted file mode 100755
index 799ac1848..000000000
--- a/tools/pretty_tox.sh
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/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 852e234ff..b3666b182 100644
--- a/tox.ini
+++ b/tox.ini
@@ -9,7 +9,6 @@ usedevelop = True
 # tox is silly... these need to be separated by a newline....
 whitelist_externals =
   find
-  bash
   rm
 passenv = ZUUL_CACHE_DIR
           REQUIREMENTS_PIP_LOCATION
@@ -20,9 +19,7 @@ deps =
   -r{toxinidir}/requirements.txt
 commands =
   find . -type f -name "*.pyc" -delete
-  bash tools/pretty_tox.sh '{posargs}'
-  # there is also secret magic in pretty_tox.sh which lets you run in a fail only
-  # mode. To do this define the TRACE_FAILONLY environmental variable.
+  stestr run {posargs}
 
 [testenv:pep8]
 basepython = python3
@@ -63,26 +60,27 @@ commands =
 [testenv:functional]
 basepython = python2.7
 passenv = OS_NOVACLIENT_TEST_NETWORK
-setenv =
-  OS_TEST_PATH = ./novaclient/tests/functional
 commands =
-  bash tools/pretty_tox.sh '--concurrency=1 {posargs}'
+  stestr --test-path=./novaclient/tests/functional run --concurrency=1 {posargs}
   python novaclient/tests/functional/hooks/check_resources.py
 
 [testenv:functional-py35]
 basepython = python3.5
 passenv = OS_NOVACLIENT_TEST_NETWORK
-setenv =
-  OS_TEST_PATH = ./novaclient/tests/functional
 commands =
-  bash tools/pretty_tox.sh '--concurrency=1 {posargs}'
+  stestr --test-path=./novaclient/tests/functional run --concurrency=1 {posargs}
   python novaclient/tests/functional/hooks/check_resources.py
 
 [testenv:cover]
 basepython = python3
+setenv =
+    PYTHON=coverage run --source novaclient --parallel-mode
 commands =
-  python setup.py testr --coverage --testr-args='{posargs}'
-  coverage report
+    stestr run {posargs}
+    coverage combine
+    coverage html -d cover
+    coverage xml -o cover/coverage.xml
+    coverage report
 
 [flake8]
 # Following checks should be enabled in the future.