File tree Expand file tree Collapse file tree 2 files changed +58
-10
lines changed
Expand file tree Collapse file tree 2 files changed +58
-10
lines changed Original file line number Diff line number Diff line change 1515if True :
1616 sys .path .insert (0 , "." )
1717 from tools .toxnox import tox_parameters
18- from tools .toxnox import extract_opts
18+ from tools .toxnox import apply_pytest_opts
1919 from tools .toxnox import OUR_PYTHON
2020
2121
@@ -173,12 +173,14 @@ def _tests(
173173 if backendonly :
174174 cmd .append ("--backend-only" )
175175
176- posargs , opts = extract_opts (session .posargs , "generate-junit" )
177-
178- if opts .generate_junit :
179- # produce individual junit files that are per-database
180- junitfile = f"junit-{ database } .xml"
181- cmd .extend (["--junitxml" , junitfile ])
176+ posargs = apply_pytest_opts (
177+ session ,
178+ "alembic" ,
179+ [
180+ database ,
181+ ],
182+ coverage = coverage ,
183+ )
182184
183185 cmd .extend (posargs )
184186
@@ -243,9 +245,13 @@ def test_pyoptimize(session: nox.Session) -> None:
243245 cmd .extend (os .environ .get ("TOX_WORKERS" , "-n4" ).split ())
244246 cmd .append ("tests/test_script_consumption.py" )
245247
246- posargs , opts = extract_opts (session .posargs , "generate-junit" )
247- if opts .generate_junit :
248- cmd .extend (["--junitxml" , "junit-pyoptimize.xml" ])
248+ posargs = apply_pytest_opts (
249+ session ,
250+ "alembic" ,
251+ [
252+ "pyoptimize" ,
253+ ],
254+ )
249255
250256 cmd .extend (posargs )
251257
Original file line number Diff line number Diff line change 1111from __future__ import annotations
1212
1313import collections
14+ import os
1415import re
1516import sys
1617from typing import Any
@@ -204,3 +205,44 @@ def extract(arg: str) -> bool:
204205 return [arg for arg in posargs if not extract (arg )], return_tuple (
205206 * return_args
206207 )
208+
209+
210+ def apply_pytest_opts (
211+ session : nox .Session ,
212+ cov : str ,
213+ tokens : list [str ],
214+ * ,
215+ coverage : bool = False ,
216+ ) -> list [str ]:
217+ posargs , opts = extract_opts (session .posargs , "generate-junit" )
218+
219+ file_suffix = "-" .join (t for t in tokens if not t .startswith ("_" ))
220+
221+ if coverage :
222+
223+ session .env ["COVERAGE_FILE" ] = coverage_file = (
224+ f".coverage.{ file_suffix } "
225+ )
226+ coverage_xml_file = f"coverage-{ file_suffix } .xml"
227+
228+ if os .path .exists (coverage_file ):
229+ os .unlink (coverage_file )
230+ posargs .extend (
231+ [
232+ f"--cov={ cov } " ,
233+ "--cov-append" ,
234+ "--cov-report" ,
235+ "term" ,
236+ "--cov-report" ,
237+ f"xml:{ coverage_xml_file } " ,
238+ ],
239+ )
240+ session .log (f"Will store coverage data in { coverage_file } " )
241+ session .log (f"Will write xml coverage data to { coverage_xml_file } " )
242+
243+ if opts .generate_junit :
244+ junitfile = f"junit-{ file_suffix } .xml"
245+ session .log (f"Will store junit xml in { junitfile } " )
246+ posargs .extend (["--junitxml" , junitfile ])
247+
248+ return posargs
You can’t perform that action at this time.
0 commit comments