Skip to content

Commit 38b701a

Browse files
committed
tests: use coverage instead of pytest-cov
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
1 parent ddf9d48 commit 38b701a

2 files changed

Lines changed: 25 additions & 21 deletions

File tree

noxfile.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@
2121

2222
from __future__ import annotations
2323

24-
import contextlib
2524
import functools
2625
import os
2726
import shutil
28-
import sqlite3
2927
import sys
3028

3129
import nox
@@ -44,31 +42,34 @@ def tests(session: nox.Session) -> None:
4442
"""Run test suite with pytest."""
4543

4644
coverage_file = f".coverage.pypi.{sys.platform}.{session.python}"
45+
env = {
46+
"PYTHONWARNDEFAULTENCODING": "1",
47+
"COVERAGE_FILE": coverage_file,
48+
}
4749

4850
session.create_tmp() # Fixes permission errors on Windows
4951
session.install(*PYPROJECT["dependency-groups"]["test"], "uv")
5052
session.install("-e.[tox-to-nox,pbs]")
5153
extra_env = {"PYTHONWARNDEFAULTENCODING": "1"}
54+
session.run("coverage", "erase", env=env)
5255
session.run(
56+
"coverage",
57+
"run",
58+
"-m",
5359
"pytest",
54-
"--cov",
55-
"--cov-config",
56-
"pyproject.toml",
57-
"--cov-report=",
5860
"--numprocesses=auto",
5961
"-m",
6062
"not conda",
6163
*session.posargs,
62-
env={
63-
"PYTHONWARNDEFAULTENCODING": "1",
64-
"COVERAGE_FILE": coverage_file,
65-
},
64+
env=env,
6665
)
66+
session.run("coverage", "combine", env=env)
67+
session.run("coverage", "report", env=env)
6768

68-
if sys.platform.startswith("win"):
69-
with contextlib.closing(sqlite3.connect(coverage_file)) as con, con:
70-
con.execute("UPDATE file SET path = REPLACE(path, '\\', '/')")
71-
con.execute("DELETE FROM file WHERE SUBSTR(path, 2, 1) == ':'")
69+
# if sys.platform.startswith("win"):
70+
# with contextlib.closing(sqlite3.connect(coverage_file)) as con, con:
71+
# con.execute("UPDATE file SET path = REPLACE(path, '\\', '/')")
72+
# con.execute("DELETE FROM file WHERE SUBSTR(path, 2, 1) == ':'")
7273

7374

7475
@nox.session(venv_backend="uv", default=False)
@@ -85,6 +86,7 @@ def xonda_tests(session: nox.Session, xonda: str) -> None:
8586
"""Run test suite set up with conda/mamba/etc."""
8687

8788
coverage_file = f".coverage.{xonda}.{sys.platform}.{session.python}"
89+
env = {"COVERAGE_FILE": coverage_file}
8890

8991
session.conda_install(
9092
"--file", "requirements-conda-test.txt", channel="conda-forge"
@@ -93,17 +95,20 @@ def xonda_tests(session: nox.Session, xonda: str) -> None:
9395
# Currently, this doesn't work on Windows either with or without quoting
9496
if not sys.platform.startswith("win32"):
9597
session.conda_install("requests<99")
98+
99+
session.run("coverage", "erase", env=env)
96100
session.run(
101+
"coverage",
102+
"run",
103+
"-m",
97104
"pytest",
98-
"--cov",
99-
"--cov-config",
100-
"pyproject.toml",
101-
"--cov-report=",
102105
"-m",
103106
"conda",
104107
*session.posargs,
105-
env={"COVERAGE_FILE": coverage_file},
108+
env=env,
106109
)
110+
session.run("coverage", "combine", env=env)
111+
session.run("coverage", "report", env=env)
107112

108113

109114
@nox.session(venv_backend="conda", default=bool(shutil.which("conda")))

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ test = [
7373
"coverage[toml]>=7.10.3",
7474
"pytest>=7.4; python_version>='3.12'",
7575
"pytest>=7; python_version<'3.12'",
76-
"pytest-cov>=3",
7776
"pytest-xdist>=3",
7877
]
7978
docs = [
@@ -137,7 +136,7 @@ run.core = "sysmon"
137136
run.branch = true
138137
run.patch = [ "subprocess" ]
139138
run.relative_files = true
140-
run.source_pkgs = [ "nox" ]
139+
run.source_dirs = [ "nox" ]
141140
run.disable_warnings = [
142141
"no-sysmon",
143142
]

0 commit comments

Comments
 (0)