From 716b37195cb9d1f124f131c2f51db3db889aa525 Mon Sep 17 00:00:00 2001
From: lb584 <lb584@cam.ac.uk>
Date: Fri, 3 Feb 2023 15:34:09 +0000
Subject: [PATCH] adding html test report

---
 .gitlab-ci.yml                                |  5 +++--
 conda-env-py3EWS-nobuilds.yml                 |  3 +++
 conda-env-py3EWS-withbuilds.yml               |  3 +++
 configs/docker/build/Dockerfile               | 14 -------------
 .../partial/integration_test_utils.py         |  3 +++
 tests/integration/partial/run_test_suite.py   | 20 +++++++++++++++++++
 6 files changed, 32 insertions(+), 16 deletions(-)
 create mode 100644 tests/integration/partial/run_test_suite.py

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 63adfad..d3fb17e 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -99,10 +99,9 @@ half_fat_tests:
 
   script:
     - cd $CI_PROJECT_DIR/tests/unit/coordinator/
-    - python3 -m coverage run -m unittest *
+    - python3 -m coverage run -m run_rest_suite.py $CI_PROJECT_DIR/test_reports
     - python -m coverage report
     - python -m coverage html -d $CI_PROJECT_DIR/coverage
-    - pytest --junitxml=report.xml
 #    - cd $CI_PROJECT_DIR/tests/integration/partial/
 #    - python3 -m coverage run -m unittest test_advisory.py
 #    - python3 -m coverage run -m unittest test_deposition.py
@@ -115,6 +114,7 @@ half_fat_tests:
     when: always
     paths:
       - $CI_PROJECT_DIR/coverage
+      - $CI_PROJECT_DIR/test_reports
     reports:
       junit: report.xml
     expire_in: 10 days
@@ -134,6 +134,7 @@ half_fat_epi_tests:
   artifacts:
     paths:
       - $CI_PROJECT_DIR/coverage
+      - $CI_PROJECT_DIR/test_reports
     expire_in: 10 days
 
 full_fat_depo:
diff --git a/conda-env-py3EWS-nobuilds.yml b/conda-env-py3EWS-nobuilds.yml
index 6dd54b6..f327285 100644
--- a/conda-env-py3EWS-nobuilds.yml
+++ b/conda-env-py3EWS-nobuilds.yml
@@ -182,4 +182,7 @@ dependencies:
   - yaml=0.2.5
   - zlib=1.2.11
   - zstd=1.5.0
+  - pip:
+      - coverage==6.5.0
+      - html-testrunner==1.2.1
 prefix: /storage/app/EWS/envs/conda/py3EWS
diff --git a/conda-env-py3EWS-withbuilds.yml b/conda-env-py3EWS-withbuilds.yml
index 91e247f..2eb778b 100644
--- a/conda-env-py3EWS-withbuilds.yml
+++ b/conda-env-py3EWS-withbuilds.yml
@@ -182,4 +182,7 @@ dependencies:
   - yaml=0.2.5=h7b6447c_0
   - zlib=1.2.11=h7f8727e_4
   - zstd=1.5.0=ha95c52a_0
+  - pip:
+      - coverage==6.5.0
+      - html-testrunner==1.2.1
 prefix: /storage/app/EWS/envs/conda/py3EWS
diff --git a/configs/docker/build/Dockerfile b/configs/docker/build/Dockerfile
index 72dd009..5affde3 100644
--- a/configs/docker/build/Dockerfile
+++ b/configs/docker/build/Dockerfile
@@ -40,20 +40,6 @@ RUN groupadd -g $GID $GNAME
 RUN useradd -m -u $UID -g $GID -o -s /bin/bash $UNAME
 USER ewsmanager
 
-#get the pythonpath ready to point at the pipeline code, which will get mounted at runtime
-ENV CODE_DIR="/storage/app/EWS_prod/code/"
-ENV flagdir=$CODE_DIR/flagdir
-ENV epimodel=$CODE_DIR/epimodel
-ENV advisory=$CODE_DIR/advisory_builder
-ENV met_processing=$CODE_DIR/met_extractor_v2/met_data_extraction
-ENV met_processor=$CODE_DIR/environmental_suitability/environmental_suitability
-ENV plotting=$CODE_DIR/plotting/plotting
-ENV post_processing=$CODE_DIR/post_processing/ews_postprocessing
-ENV source_gen=$CODE_DIR/source_gen
-ENV coordinator=$CODE_DIR/coordinator/coordinator
-ENV coordinator_tests=$CODE_DIR/coordinator/tests
-ENV PYTHONPATH=$PYTHONPATH:$flagdir:$epimodel:$advisory:$met_processing:$met_processor:$plotting:$source_gen:$post_processing:$coordinator:$coordinator_tests
-
 RUN echo $PYTHONPATH
 
 WORKDIR /home/ewsmanager
diff --git a/tests/integration/partial/integration_test_utils.py b/tests/integration/partial/integration_test_utils.py
index 4e383b2..943f0d1 100644
--- a/tests/integration/partial/integration_test_utils.py
+++ b/tests/integration/partial/integration_test_utils.py
@@ -2,6 +2,7 @@ import glob
 import json
 import os
 from datetime import datetime
+from importlib import reload
 from typing import List
 from zipfile import ZipFile
 
@@ -81,6 +82,8 @@ class IntegrationTestUtils:
 
         #  need EMAIL_CRED in the environment before we import Processor
         os.environ["EMAIL_CRED"] = IntegrationTestUtils.EMAIL_CRED_PATH
+        import Processor
+        reload(Processor)
         from Processor import run_Process, set_log_level
 
         args_dict: dict = {}
diff --git a/tests/integration/partial/run_test_suite.py b/tests/integration/partial/run_test_suite.py
new file mode 100644
index 0000000..4403301
--- /dev/null
+++ b/tests/integration/partial/run_test_suite.py
@@ -0,0 +1,20 @@
+import sys
+from unittest import TestLoader, TestSuite
+
+from HtmlTestRunner import HTMLTestRunner
+
+
+from integration.partial.test_deposition import TestDeposition
+from integration.partial.test_env_suit import TestEnvSuit
+
+
+def run_tests_and_report(output: str):
+    tests: TestSuite = TestLoader().loadTestsFromTestCase(TestDeposition)
+    tests.addTests(TestLoader().loadTestsFromTestCase(TestEnvSuit))
+    runner = HTMLTestRunner(output=output, combine_reports = True)
+
+    runner.run(tests)
+
+
+if __name__ == '__main__':
+    run_tests_and_report(sys.argv[1])
-- 
GitLab