]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
update toxnox with newer coverage/junit approach
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 29 Oct 2025 12:38:39 +0000 (08:38 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 29 Oct 2025 12:38:39 +0000 (08:38 -0400)
Change-Id: Ieecafab1f929ed9afe0b0675acbeceaecc25e48e

noxfile.py
tools/toxnox.py

index 965c58755c590ac4557aa02ec84507fa7df2f9e4..079df2d50c28622af8b48c8c1fd8dcb1d11c8d11 100644 (file)
@@ -15,7 +15,7 @@ nox.needs_version = ">=2025.10.16"
 if True:
     sys.path.insert(0, ".")
     from tools.toxnox import tox_parameters
-    from tools.toxnox import extract_opts
+    from tools.toxnox import apply_pytest_opts
     from tools.toxnox import OUR_PYTHON
 
 
@@ -173,12 +173,14 @@ def _tests(
     if backendonly:
         cmd.append("--backend-only")
 
-    posargs, opts = extract_opts(session.posargs, "generate-junit")
-
-    if opts.generate_junit:
-        # produce individual junit files that are per-database
-        junitfile = f"junit-{database}.xml"
-        cmd.extend(["--junitxml", junitfile])
+    posargs = apply_pytest_opts(
+        session,
+        "alembic",
+        [
+            database,
+        ],
+        coverage=coverage,
+    )
 
     cmd.extend(posargs)
 
@@ -243,9 +245,13 @@ def test_pyoptimize(session: nox.Session) -> None:
     cmd.extend(os.environ.get("TOX_WORKERS", "-n4").split())
     cmd.append("tests/test_script_consumption.py")
 
-    posargs, opts = extract_opts(session.posargs, "generate-junit")
-    if opts.generate_junit:
-        cmd.extend(["--junitxml", "junit-pyoptimize.xml"])
+    posargs = apply_pytest_opts(
+        session,
+        "alembic",
+        [
+            "pyoptimize",
+        ],
+    )
 
     cmd.extend(posargs)
 
index 891fc70f9c42c4d1ee31c513681c58540c7147e7..64bd298df570af75d637da3efdfe78b85d7bc3aa 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
@@ -204,3 +205,44 @@ 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 apply_pytest_opts(
+    session: nox.Session,
+    cov: str,
+    tokens: list[str],
+    *,
+    coverage: bool = False,
+) -> list[str]:
+    posargs, opts = extract_opts(session.posargs, "generate-junit")
+
+    file_suffix = "-".join(t for t in tokens if not t.startswith("_"))
+
+    if coverage:
+
+        session.env["COVERAGE_FILE"] = coverage_file = (
+            f".coverage.{file_suffix}"
+        )
+        coverage_xml_file = f"coverage-{file_suffix}.xml"
+
+        if os.path.exists(coverage_file):
+            os.unlink(coverage_file)
+        posargs.extend(
+            [
+                f"--cov={cov}",
+                "--cov-append",
+                "--cov-report",
+                "term",
+                "--cov-report",
+                f"xml:{coverage_xml_file}",
+            ],
+        )
+        session.log(f"Will store coverage data in {coverage_file}")
+        session.log(f"Will write xml coverage data to {coverage_xml_file}")
+
+    if opts.generate_junit:
+        junitfile = f"junit-{file_suffix}.xml"
+        session.log(f"Will store junit xml in {junitfile}")
+        posargs.extend(["--junitxml", junitfile])
+
+    return posargs