2121
2222from __future__ import annotations
2323
24- import contextlib
2524import functools
2625import os
2726import shutil
28- import sqlite3
2927import sys
3028
3129import nox
4341def tests (session : nox .Session ) -> None :
4442 """Run test suite with pytest."""
4543
46- coverage_file = f".coverage.{ sys .platform } .{ session .python } "
44+ coverage_file = f".coverage.pypi.{ sys .platform } .{ session .python } "
45+ env = {
46+ "PYTHONWARNDEFAULTENCODING" : "1" ,
47+ "COVERAGE_FILE" : coverage_file ,
48+ }
49+ parallel = [] if sys .platform .startswith ("win32" ) else ["--numprocesses=auto" ]
4750
4851 session .create_tmp () # Fixes permission errors on Windows
4952 session .install (* PYPROJECT ["dependency-groups" ]["test" ], "uv" )
5053 session .install ("-e.[tox-to-nox,pbs]" )
51- 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=" ,
60+ * parallel ,
61+ "-m" ,
62+ "not conda" ,
5863 * session .posargs ,
59- env = {
60- "COVERAGE_FILE" : coverage_file ,
61- ** extra_env ,
62- },
64+ env = env ,
6365 )
64-
65- if sys .platform .startswith ("win" ):
66- with contextlib .closing (sqlite3 .connect (coverage_file )) as con , con :
67- con .execute ("UPDATE file SET path = REPLACE(path, '\\ ', '/')" )
68- con .execute ("DELETE FROM file WHERE SUBSTR(path, 2, 1) == ':'" )
66+ session .run ("coverage" , "combine" , env = env )
67+ session .run ("coverage" , "report" , env = env )
6968
7069
7170@nox .session (venv_backend = "uv" , default = False )
@@ -75,45 +74,54 @@ def minimums(session: nox.Session) -> None:
7574
7675 session .install ("-e." , "--group=test" , "--resolution=lowest-direct" )
7776 session .run ("uv" , "pip" , "list" )
78- session .run ("pytest" , * session .posargs )
77+ session .run ("pytest" , "-m" , "not conda" , * session .posargs )
7978
8079
81- @nox .session (venv_backend = "conda" , default = bool (shutil .which ("conda" )))
82- def conda_tests (session : nox .Session ) -> None :
83- """Run test suite set up with conda."""
80+ def xonda_tests (session : nox .Session , xonda : str ) -> None :
81+ """Run test suite set up with conda/mamba/etc."""
82+
83+ coverage_file = f".coverage.{ xonda } .{ sys .platform } .{ session .python } "
84+ env = {"COVERAGE_FILE" : coverage_file }
85+
8486 session .conda_install (
8587 "--file" , "requirements-conda-test.txt" , channel = "conda-forge"
8688 )
8789 session .install ("-e." , "--no-deps" )
8890 # Currently, this doesn't work on Windows either with or without quoting
8991 if not sys .platform .startswith ("win32" ):
9092 session .conda_install ("requests<99" )
91- session .run ("pytest" , * session .posargs )
93+
94+ session .run ("coverage" , "erase" , env = env )
95+ session .run (
96+ "coverage" ,
97+ "run" ,
98+ "-m" ,
99+ "pytest" ,
100+ "-m" ,
101+ "conda" ,
102+ * session .posargs ,
103+ env = env ,
104+ )
105+ session .run ("coverage" , "combine" , env = env )
106+ session .run ("coverage" , "report" , env = env )
107+
108+
109+ @nox .session (venv_backend = "conda" , default = bool (shutil .which ("conda" )))
110+ def conda_tests (session : nox .Session ) -> None :
111+ """Run test suite set up with conda."""
112+ xonda_tests (session , "conda" )
92113
93114
94115@nox .session (venv_backend = "mamba" , default = shutil .which ("mamba" ))
95116def mamba_tests (session : nox .Session ) -> None :
96117 """Run test suite set up with mamba."""
97- session .conda_install (
98- "--file" , "requirements-conda-test.txt" , channel = "conda-forge"
99- )
100- session .install ("-e." , "--no-deps" )
101- if not sys .platform .startswith ("win32" ):
102- session .conda_install ("requests<99" )
103- session .run ("pytest" , * session .posargs )
118+ xonda_tests (session , "mamba" )
104119
105120
106121@nox .session (venv_backend = "micromamba" , default = shutil .which ("micromamba" ))
107122def micromamba_tests (session : nox .Session ) -> None :
108123 """Run test suite set up with micromamba."""
109- session .conda_install (
110- "--file" , "requirements-conda-test.txt" , channel = "conda-forge"
111- )
112- # Currently, this doesn't work on Windows either with or without quoting
113- session .install ("-e." , "--no-deps" )
114- if not sys .platform .startswith ("win32" ):
115- session .conda_install ("requests<99" )
116- session .run ("pytest" , * session .posargs )
124+ xonda_tests (session , "micromamba" )
117125
118126
119127@nox .session (default = False )
0 commit comments