From 9c761869edb88090caf7386bb72b761e6350ce10 Mon Sep 17 00:00:00 2001
From: lukken <lukken@astron.nl>
Date: Tue, 11 Jan 2022 12:20:07 +0000
Subject: [PATCH] L2SS-313: Resolve access to coverage as module

---
 .gitignore                                    |  1 +
 .../tangostationcontrol/beam/__init__.py      |  0
 tangostationcontrol/tox.ini                   | 28 +++++++++++++------
 3 files changed, 21 insertions(+), 8 deletions(-)
 create mode 100644 tangostationcontrol/tangostationcontrol/beam/__init__.py

diff --git a/.gitignore b/.gitignore
index 130dd056a..00941bb5a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -22,6 +22,7 @@ tangostationcontrol/dist
 tangostationcontrol/docs/build
 
 **/coverage.xml
+**/.coverage
 **/.ipynb_checkpoints
 **/pending_log_messages.db
 **/.eggs
diff --git a/tangostationcontrol/tangostationcontrol/beam/__init__.py b/tangostationcontrol/tangostationcontrol/beam/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/tangostationcontrol/tox.ini b/tangostationcontrol/tox.ini
index fbde7d74e..d2f6776e7 100644
--- a/tangostationcontrol/tox.ini
+++ b/tangostationcontrol/tox.ini
@@ -26,19 +26,31 @@ setenv = TESTS_DIR=./tangostationcontrol/integration_test
 commands =
     stestr run --serial {posargs}
 
+; The access to coverage as module is a bit of an ugly hack. This is due to
+; cover inheriting testenv which has `sitepackages = True`, meaning that global
+; packages can be accessed by the tox environment. Our tango images already have
+; coverage system wide installed, however, the system wide installation will
+; never look inside tox its virtualenv for packages. So accessing stestr and
+; others fail.. We can't remove `sitepackages = True` either as we need access
+; to tango and installing this package is non-trivial. The solution is to
+; prevent calling binaries directly and utilizing python to resolve the
+; requested module. In addition stestr does not natively support generating
+; coverage reports which is where the `PYTHON=python -m coverage run....` comes
+; from.
 [testenv:cover]
-allowlist_externals =
-    coverage
+setenv =
+    VIRTUAL_ENV={envdir}
+    PYTHON=python -m coverage run --source tangostationcontrol --parallel-mode
 deps =
     -r{toxinidir}/test-requirements.txt
     -r{toxinidir}/../docker-compose/lofar-device-base/lofar-requirements.txt
 commands =
-    coverage erase
-    stestr run {posargs}
-    coverage combine
-    coverage html -d cover
-    coverage xml -o coverage.xml
-    coverage report
+  python -m coverage erase
+  stestr run {posargs}
+  python -m coverage combine
+  python -m coverage html -d cover
+  python -m coverage xml -o coverage.xml
+  python -m coverage report
 
 ; TODO(Corne): Integrate Hacking to customize pep8 rules
 [testenv:pep8]
-- 
GitLab