From b7dcfd05faef81fad174489ad80ed22dab020518 Mon Sep 17 00:00:00 2001
From: ale <ale@incal.net>
Date: Thu, 2 Jan 2025 18:15:50 +0100
Subject: [PATCH] Use pytest, generate JUnit output

The artifacts are saved outside of the test container and retrieved
to the CI runner.
---
 test/Dockerfile           |  4 ++--
 test/integration-test.yml | 19 ++++++++++++++++++-
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/test/Dockerfile b/test/Dockerfile
index 4cf0707f..c4b64355 100644
--- a/test/Dockerfile
+++ b/test/Dockerfile
@@ -1,7 +1,7 @@
 FROM debian:stable
 
 RUN apt-get -q update && env DEBIAN_FRONTEND=noninteractive \
-    apt-get install --no-install-recommends -y python3 python3-pip python3-setuptools python3-yaml python3-jinja2 python3-nose python3-dnspython
+    apt-get install --no-install-recommends -y python3 python3-pip python3-setuptools python3-yaml python3-jinja2 python3-pytest python3-dnspython
 
 ADD . /src
 WORKDIR /src
@@ -9,4 +9,4 @@ RUN python3 setup.py install
 
 ENV TEST_CONFIG=/test-config.yml
 ENV TEST_PARAMS=/src/float_integration_test/test-params.yml
-CMD ["nosetests3", "-v", "float_integration_test"]
+CMD ["pytest", "-v", "-junit_xml=/artifacts/pytest.xml", "float_integration_test"]
diff --git a/test/integration-test.yml b/test/integration-test.yml
index e43a784e..bff929ae 100644
--- a/test/integration-test.yml
+++ b/test/integration-test.yml
@@ -8,13 +8,30 @@
         dest: /tmp/test-config.yml
         content: "{{ vars | to_nice_yaml }}"
 
+    - name: Create test artifact directory
+      file:
+        path: "/artifacts"
+        state: directory
+        mode: "01777"
+
     - name: Pull the test suite container image
       command: "float-pull-image {{ test_image }}"
       register: test_container_image
       failed_when: "test_container_image.rc not in [0, 42]"
 
     - name: Run tests
-      command: "podman run --rm --network host --mount type=bind,source=/tmp/test-config.yml,destination=/test-config.yml {{ test_image }}"
+      command: "podman run --rm --network host --mount type=bind,source=/tmp/test-config.yml,destination=/test-config.yml --mount type=bind,source=/artifacts,destination=/artifacts {{ test_image }}"
+
+    - name: Retrieve test result
+      slurp:
+        src: "/artifacts/pytest.xml"
+      register: pytest_xml
+
+    - name: Store test results locally
+      local_action:
+        module: copy
+        dest: "pytest.xml"
+        content: "{{ pytest_xml['content'] | b64decode }}"
 
   vars:
     test_image: "registry.git.autistici.org/ai3/float:integration-test"
-- 
GitLab