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
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)
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)
from __future__ import annotations
import collections
+import os
import re
import sys
from typing import 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