]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
move junit logic to toxnox
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 6 Oct 2025 20:19:14 +0000 (16:19 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 6 Oct 2025 20:19:14 +0000 (16:19 -0400)
Change-Id: Ica686abc8f17cc46a663d7452b59e8c436e2971e

noxfile.py
tools/toxnox.py

index 1be66de98049478ff854a6dc98fd7157bd5c8cc6..dffbf9d79e62c56905d944965f251250bde4145b 100644 (file)
@@ -12,6 +12,7 @@ from packaging.version import parse as parse_version
 
 if True:
     sys.path.insert(0, ".")
+    from tools.toxnox import move_junit_file
     from tools.toxnox import tox_parameters
     from tools.toxnox import extract_opts
 
@@ -168,17 +169,8 @@ def _tests(
 
     posargs, opts = extract_opts(session.posargs, "generate-junit")
 
-    # produce individual junit files that are per-database (or as close as we
-    # can get).  jenkins junit plugin will merge all the files...
-    if len(databases) == 1:
-        junitfile = f"junit-{databases[0]}.xml"
-        suite_name = f"pytest-{databases[0]}"
-    else:
-        junitfile = "junit-general.xml"
-        suite_name = "pytest-general"
-
     if opts.generate_junit:
-        cmd.extend(["--junitxml", junitfile])
+        cmd.extend(["--junitxml", "junit-tmp.xml"])
 
     cmd.extend(posargs)
 
@@ -188,12 +180,17 @@ def _tests(
     # get merged we can view each suite distinctly rather than them getting
     # overwritten with each other since they are running the same tests
     if opts.generate_junit:
-        import junitparser
 
-        xml = junitparser.JUnitXml.fromfile(junitfile)
-        for suite in xml:
-            suite.name = suite_name
-        xml.write(junitfile)
+        # produce individual junit files that are per-database (or as close as
+        # we can get).  jenkins junit plugin will merge all the files...
+        if len(databases) == 1:
+            junitfile = f"junit-{databases[0]}.xml"
+            suite_name = f"pytest-{databases[0]}"
+        else:
+            junitfile = "junit-general.xml"
+            suite_name = "pytest-general"
+
+        move_junit_file("junit-tmp.xml", junitfile, suite_name)
 
     # Run cleanup for oracle/mssql
     for database in databases:
index 497a689c613fb3a70c0c73d7776133053439c656..b64b71a7c3b380a7b666045081f34a7b03e31213 100644 (file)
@@ -11,6 +11,7 @@ would fall back to defaults.
 from __future__ import annotations
 
 import collections
+import os
 import re
 import sys
 from typing import Any
@@ -215,3 +216,13 @@ def extract_opts(posargs: List[str], *args: str) -> Tuple[List[str], Any]:
     return [arg for arg in posargs if not extract(arg)], return_tuple(
         *return_args
     )
+
+
+def move_junit_file(tmpfilename: str, newname: str, suite_name: str):
+    import junitparser
+
+    xml = junitparser.JUnitXml.fromfile(tmpfilename)
+    for suite in xml:
+        suite.name = suite_name
+    xml.write(newname)
+    os.unlink(tmpfilename)