Skip to content

Commit 2f58936

Browse files
committed
nox refinements
get rid of _tests() calling session.run() multiple times, do the full list in one run. for backends, typically we will use multiple entries under -t in any case. Change-Id: I93170ece8d8639eb77e43d4451e8e6f3dbefde68
1 parent e8cd57c commit 2f58936

2 files changed

Lines changed: 52 additions & 52 deletions

File tree

noxfile.py

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from __future__ import annotations
44

5+
import glob
6+
import itertools
57
import os
68
import sys
79

@@ -83,22 +85,6 @@ def test_backends(session: nox.Session, target: str, full: str) -> None:
8385
_tests(session, [target], full=full == "full")
8486

8587

86-
@nox.session(name="all")
87-
@tox_parameters(
88-
["python", "target", "full"],
89-
[PYTHON_VERSIONS, ["all"], FULL],
90-
always_include_in_tag=["target"],
91-
)
92-
def tests_all(session: nox.Session, target: str, full: str) -> None:
93-
"""Run the main test suite against all backends separately"""
94-
95-
_tests(
96-
session,
97-
TARGETS,
98-
full=full == "full",
99-
)
100-
101-
10288
@nox.session(name="coverage")
10389
@tox_parameters(["target"], [TARGETS], base_tag="coverage")
10490
def coverage(session: nox.Session, target: str) -> None:
@@ -138,23 +124,28 @@ def _tests(
138124
]
139125
)
140126

141-
if full:
142-
# enables all tags including time_intensive
143-
cmd.extend(["-m", ""])
127+
if not full:
128+
# disable time_intensive
129+
cmd.extend(["-m", "not time_intensive"])
144130

145-
for target in targets:
146-
# due to the pifpaf thing, it's easier just to run all the
147-
# pytests separately for each backend rather than having all the
148-
# services running and figuring out how to keep them all on distinct
149-
# ports. so iterate through backends and run individual suites.
150-
backend_cmd: list[str] = []
151-
pifpaf_cmd: list[str] = []
131+
backend_cmd: list[str] = []
132+
pifpaf_cmd: list[str] = []
152133

134+
ports = itertools.count(11212)
135+
136+
for target in targets:
153137
# note the default target is "generic", which means run all the
154138
# normal tests but no backend tests
139+
155140
match target:
156141
case "generic":
157-
backend_cmd.append("-k not backend.py")
142+
backend_cmd.extend(
143+
[
144+
path
145+
for path in glob.glob("tests/**/*.py", recursive=True)
146+
if "backend" not in path
147+
]
148+
)
158149
case "memory":
159150
backend_cmd.append("tests/cache/test_memory_backend.py")
160151
case "memcached":
@@ -165,12 +156,16 @@ def _tests(
165156
)
166157
)
167158

168-
pifpaf(pifpaf_cmd, "memcached")
159+
pifpaf(
160+
pifpaf_cmd,
161+
"memcached",
162+
port=str(next(ports)),
163+
)
169164
pifpaf(
170165
pifpaf_cmd,
171166
"memcached",
172167
port_env="TOX_DOGPILE_TLS_PORT",
173-
port="11212",
168+
port=str(next(ports)),
174169
additonal_args=(
175170
"--ssl_chain_cert=tests/tls/server_chain.pem "
176171
"--ssl_key=tests/tls/server.key"
@@ -182,13 +177,13 @@ def _tests(
182177
session.install(
183178
*nox.project.dependency_groups(pyproject, "tests_redis")
184179
)
185-
pifpaf(pifpaf_cmd, "redis")
180+
pifpaf(pifpaf_cmd, "redis", port=str(next(ports)))
186181
backend_cmd.append("tests/cache/test_redis_backend.py")
187182
case "valkey":
188183
session.install(
189184
*nox.project.dependency_groups(pyproject, "tests_valkey")
190185
)
191-
pifpaf(pifpaf_cmd, "valkey")
186+
pifpaf(pifpaf_cmd, "valkey", port=str(next(ports)))
192187
backend_cmd.append("tests/cache/test_valkey_backend.py")
193188
case "redis_sentinel":
194189
session.install(
@@ -198,9 +193,11 @@ def _tests(
198193
pifpaf(
199194
pifpaf_cmd,
200195
"redis",
196+
port=str(next(ports)),
201197
additonal_args=f"--sentinel --sentinel "
202198
f"--sentinel-port "
203-
f"{os.environ.get('TOX_DOGPILE_SENTINEL_PORT', '11235')}",
199+
f"""{os.environ.get(
200+
'TOX_DOGPILE_SENTINEL_PORT', str(next(ports)))}""",
204201
)
205202
backend_cmd.append(
206203
"tests/cache/test_redis_sentinel_backend.py"
@@ -212,36 +209,39 @@ def _tests(
212209
pifpaf(
213210
pifpaf_cmd,
214211
"valkey",
212+
port=str(next(ports)),
215213
additonal_args=f"--sentinel --sentinel "
216214
f"--sentinel-port "
217-
f"{os.environ.get('TOX_DOGPILE_SENTINEL_PORT', '11235')}",
215+
f"""{os.environ.get(
216+
'TOX_DOGPILE_SENTINEL_PORT', str(next(ports)))}""",
218217
)
219218
backend_cmd.append(
220219
"tests/cache/test_valkey_sentinel_backend.py"
221220
)
222221
case "dbm":
223222
backend_cmd.append("tests/cache/test_dbm_backend.py")
224223

225-
posargs, opts = extract_opts(session.posargs, "generate-junit")
224+
posargs, opts = extract_opts(session.posargs, "generate-junit")
225+
226+
if opts.generate_junit:
227+
cmd.extend(["--junitxml", "junit-tmp.xml"])
226228

229+
try:
230+
session.run(*pifpaf_cmd, *cmd, *backend_cmd, *posargs)
231+
finally:
232+
# name the suites distinctly as well. this is so that when they
233+
# get merged we can view each suite distinctly rather than them
234+
# getting overwritten with each other since they are running the
235+
# same tests
227236
if opts.generate_junit:
228-
cmd.extend(["--junitxml", "junit-tmp.xml"])
229-
230-
try:
231-
session.run(*pifpaf_cmd, *cmd, *backend_cmd, *posargs)
232-
finally:
233-
# name the suites distinctly as well. this is so that when they
234-
# get merged we can view each suite distinctly rather than them
235-
# getting overwritten with each other since they are running the
236-
# same tests
237-
if opts.generate_junit:
238-
# produce individual junit files that are per-database (or as
239-
# close as we can get). jenkins junit plugin will merge all
240-
# the files...
241-
junitfile = f"junit-{target}.xml"
242-
suite_name = f"pytest-{target}"
243-
244-
move_junit_file("junit-tmp.xml", junitfile, suite_name)
237+
# produce individual junit files that are per-database (or as
238+
# close as we can get). jenkins junit plugin will merge all
239+
# the files...
240+
junit_suffix = "-".join(targets)
241+
junitfile = f"junit-{junit_suffix}.xml"
242+
suite_name = f"pytest-{junit_suffix}"
243+
244+
move_junit_file("junit-tmp.xml", junitfile, suite_name)
245245

246246

247247
@nox.session(name="pep484")

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ ignore_missing_imports = true
162162
warn_unused_ignores = true
163163

164164
[tool.pytest.ini_options]
165-
addopts = "--tb native -v -r fxX -p no:logging -p no:warnings -m 'not time_intensive'"
165+
addopts = "--tb native -v -r fxX -p no:logging -p no:warnings"
166166
python_files = "tests/*test_*.py"
167167
python_classes = "*Test"
168168
filterwarnings = [

0 commit comments

Comments
 (0)