From c574d7281150a9f833525651eac4b1f202abcb71 Mon Sep 17 00:00:00 2001
From: lukas leufen <l.leufen@fz-juelich.de>
Date: Mon, 11 Nov 2019 09:48:38 +0100
Subject: [PATCH] report test results as html for easy inspection, bugfix in
 tests

---
 .gitlab-ci.yml              |  6 ++++++
 CI/run_pytest.sh            | 13 ++++++++++++-
 requirements.txt            |  1 +
 test/test_data_generator.py |  4 ++--
 4 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 1ef531ba..c34d9a24 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -47,6 +47,7 @@ tests:
     when: always
     paths:
       - badges/
+      - test/
 
 coverage:
   tags:
@@ -88,6 +89,9 @@ pages:
     - mkdir -p public/coverage
     - cp -af coverage/. public/coverage
     - ls public/coverage
+    - mkdir -p public/test
+    - cp -af test/. public/test
+    - ls public/test
     - ls public
   when: always
   artifacts:
@@ -97,8 +101,10 @@ pages:
       - public
       - badges/
       - coverage/
+      - test/
   cache:
     key: old-pages
     paths:
       - public/badges/
       - public/coverage/
+      - public/test/
diff --git a/CI/run_pytest.sh b/CI/run_pytest.sh
index 4ba24b11..d8755448 100644
--- a/CI/run_pytest.sh
+++ b/CI/run_pytest.sh
@@ -1,10 +1,21 @@
 #!/bin/bash
 
 # run pytest for all modules
-python3 -m pytest test/ | tee test_results.out
+python3 -m pytest --html=report.html --self-contained-html test/ | tee test_results.out
 
 IS_FAILED=$?
 
+# move html test report
+mkdir test/
+BRANCH_NAME=$( echo -e "${CI_COMMIT_REF_NAME////_}")
+mkdir test/${BRANCH_NAME}
+mkdir test/recent
+cp report.html test/${BRANCH_NAME}/.
+cp report.html test/recent/.
+if [[ "${CI_COMMIT_REF_NAME}" = "master" ]]; then
+    cp -r report.html test/.
+fi
+
 # exit 0 if no tests implemented
 RUN_NO_TESTS="$(grep -c 'no tests ran' test_results.out)"
 if [[ ${RUN_NO_TESTS} > 0 ]]; then
diff --git a/requirements.txt b/requirements.txt
index 4f4c9fd2..cdf03578 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -7,4 +7,5 @@ requests==2.22.0
 pytest==5.2.1
 pytest-lazy-fixture==0.6.1
 pytest-cov
+pytest-html
 pydot
diff --git a/test/test_data_generator.py b/test/test_data_generator.py
index 12162c7d..30846476 100644
--- a/test/test_data_generator.py
+++ b/test/test_data_generator.py
@@ -43,9 +43,9 @@ class TestDataGenerator:
         assert len(gen) == 3
 
     def test_iter(self, gen):
-        assert hasattr(gen, 'iterator') is False
+        assert hasattr(gen, '_iterator') is False
         iter(gen)
-        assert hasattr(gen, 'iterator')
+        assert hasattr(gen, '_iterator')
         assert gen._iterator == 0
 
     def test_next(self, gen):
-- 
GitLab