From: Mike Bayer Date: Mon, 6 Oct 2025 20:19:14 +0000 (-0400) Subject: move junit logic to toxnox X-Git-Tag: rel_1_17_0~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9533b11927b5a493466e61747ed3ce6d53b155ab;p=thirdparty%2Fsqlalchemy%2Falembic.git move junit logic to toxnox Change-Id: Ica686abc8f17cc46a663d7452b59e8c436e2971e --- diff --git a/noxfile.py b/noxfile.py index 1be66de9..dffbf9d7 100644 --- a/noxfile.py +++ b/noxfile.py @@ -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: diff --git a/tools/toxnox.py b/tools/toxnox.py index 497a689c..b64b71a7 100644 --- a/tools/toxnox.py +++ b/tools/toxnox.py @@ -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)