| 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 | if session.python and isinstance(session.python, str): |
| 220 | python_token = session.python.replace(".", "") |
| 221 | tokens.insert(0, python_token) |
| 222 | |
| 223 | file_suffix = "-".join(t for t in tokens if not t.startswith("_")) |
| 224 | |
| 225 | if coverage: |
| 226 | |
| 227 | session.env["COVERAGE_FILE"] = coverage_file = ( |
| 228 | f".coverage.{file_suffix}" |
| 229 | ) |
| 230 | coverage_xml_file = f"coverage-{file_suffix}.xml" |
| 231 | |
| 232 | if os.path.exists(coverage_file): |
| 233 | os.unlink(coverage_file) |
| 234 | posargs.extend( |
| 235 | [ |
| 236 | f"--cov={cov}", |
| 237 | "--cov-append", |
| 238 | "--cov-report", |
| 239 | "term", |
| 240 | "--cov-report", |
| 241 | f"xml:{coverage_xml_file}", |
| 242 | ], |
| 243 | ) |
| 244 | session.log(f"Will store coverage data in {coverage_file}") |
| 245 | session.log(f"Will write xml coverage data to {coverage_xml_file}") |
| 246 | |
| 247 | if opts.generate_junit: |
| 248 | junitfile = f"junit-{file_suffix}.xml" |
| 249 | session.log(f"Will store junit xml in {junitfile}") |
| 250 | posargs.extend(["--junitxml", junitfile]) |
| 251 | |
| 252 | return posargs |