Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit f170cfd

Browse files
committed
tests: refactor fragment test
1 parent b27f741 commit f170cfd

1 file changed

Lines changed: 16 additions & 23 deletions

File tree

noxfile.py

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def __call__(self, frag):
156156
else:
157157
# Run the fragment's generated unit tests.
158158
# Don't bother parallelizing them: we already parallelize
159-
# # the fragments, and there usually aren't too many tests per fragment.
159+
# # the fragments, and there usually aren't too many tests per fragment.
160160
outputs.append(
161161
self.session.run(
162162
"py.test",
@@ -167,7 +167,7 @@ def __call__(self, frag):
167167
str(Path(tmp_dir) / "tests" / "unit"),
168168
silent=True,
169169
)
170-
)
170+
)
171171

172172
return "".join(outputs)
173173

@@ -184,37 +184,30 @@ def fragment(session, use_ads_templates=False):
184184
)
185185
session.install("-e", ".")
186186

187-
# The specific failure is `Plugin output is unparseable`
188187
if session.python in ("3.9", "3.10"):
189188
session.install("google-api-core<2.28")
190189

191190
frag_files = (
192191
[Path(f) for f in session.posargs] if session.posargs else FRAGMENT_FILES
193192
)
194193

195-
if os.environ.get("PARALLEL_FRAGMENT_TESTS", "false").lower() == "true":
196-
with ThreadPoolExecutor() as p:
197-
all_outs = p.map(FragTester(session, use_ads_templates), frag_files)
194+
is_parallel = os.environ.get("PARALLEL_FRAGMENT_TESTS", "").lower() == "true"
198195

199-
output = "".join(all_outs)
200-
session.log(output)
201-
else:
202-
tester = FragTester(session, use_ads_templates)
203-
for frag in frag_files:
204-
session.log(tester(frag))
196+
def run_tests(mypy_only=False):
197+
"""Helper to handle the parallel vs sequential toggle."""
198+
tester = FragTester(session, use_ads_templates, mypy_only=mypy_only)
199+
200+
if is_parallel:
201+
with ThreadPoolExecutor() as p:
202+
results = p.map(tester, frag_files)
203+
session.log("".join(results))
204+
else:
205+
for frag in frag_files:
206+
session.log(tester(frag))
205207

206-
# now test mypy
208+
run_tests(mypy_only=False)
207209
session.install("mypy", "types-protobuf", "types-requests")
208-
if os.environ.get("PARALLEL_FRAGMENT_TESTS", "false").lower() == "true":
209-
with ThreadPoolExecutor() as p:
210-
all_outs = p.map(FragTester(session, use_ads_templates, mypy_only=True), frag_files)
211-
212-
output = "".join(all_outs)
213-
session.log(output)
214-
else:
215-
tester = FragTester(session, use_ads_templates, mypy_only=True)
216-
for frag in frag_files:
217-
session.log(tester(frag))
210+
run_tests(mypy_only=True)
218211

219212

220213
@nox.session(python=ALL_PYTHON)

0 commit comments

Comments
 (0)