Skip to content

Commit 023dd32

Browse files
committed
chore(tests/integration): introduce a FULL_TEST flag for long-running tests
@full_test
1 parent 28e2e82 commit 023dd32

File tree

3 files changed

+105
-31
lines changed

3 files changed

+105
-31
lines changed

tasks.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# Invoke is broken on Python 3.11
22
# https://github.com/pyinvoke/invoke/issues/833#issuecomment-1293148106
33
import inspect
4+
import json
45
import os
56
import re
67
import sys
8+
from pathlib import Path
79
from typing import Optional
810

911
if not hasattr(inspect, "getargspec"):
@@ -163,6 +165,7 @@ def lint(context):
163165
def test_integration(
164166
context,
165167
focus=None,
168+
full=False,
166169
debug=False,
167170
):
168171
clean_itest_artifacts(context)
@@ -176,13 +179,17 @@ def test_integration(
176179
focus_or_none = f"--filter {focus}" if focus else ""
177180
debug_opts = "-vv --show-all" if debug else ""
178181

182+
full = full or _is_full_ci_test()
183+
param_full_test = "--param HTML2PDF4DOC_FULL_TEST=1" if full else ""
184+
179185
# For now, the --threads are set to 1 because running tests parallelized
180186
# will result in race conditions between Web Driver Manager downloading
181187
# ChromeDriver.
182188
itest_command = f"""
183189
lit
184190
--threads 1
185191
--param HTML2PDF4DOC_EXEC="{html2pdf_exec}"
192+
{param_full_test}
186193
-v
187194
{debug_opts}
188195
{focus_or_none}
@@ -340,3 +347,54 @@ def test_docker(context, image: str = "html2pdf4doc:latest"):
340347
"cd tests/integration/01_hello_world && html2pdf4doc print index.html /data/output/index.pdf"
341348
),
342349
)
350+
351+
352+
def _is_full_ci_test() -> bool:
353+
"""
354+
Determine whether @full_test was requested in a GitHub CI run.
355+
Returns True if the tag is found in PR body/title or commit message.
356+
Returns False for local runs or when tag not found.
357+
"""
358+
event_name = os.getenv("GITHUB_EVENT_NAME")
359+
event_path = os.getenv("GITHUB_EVENT_PATH")
360+
361+
# No GitHub env (e.g. local run)
362+
if not event_name or not event_path or not Path(event_path).exists():
363+
print( # noqa: T201
364+
"[is_full_ci_test] No GitHub environment detected — running in local mode."
365+
)
366+
return False
367+
368+
try:
369+
with open(event_path, encoding="utf-8") as f:
370+
event = json.load(f)
371+
except Exception as e:
372+
print( # noqa: T201
373+
f"[is_full_ci_test] Failed to parse event file: {e}"
374+
)
375+
return False
376+
377+
tag = "@full_test"
378+
379+
# Check PR body/title
380+
if event_name == "pull_request":
381+
pr = event.get("pull_request", {})
382+
body = (pr.get("body") or "").lower()
383+
title = (pr.get("title") or "").lower()
384+
if tag in body or tag in title:
385+
print( # noqa: T201
386+
"[is_full_ci_test] Detected @full_test in PR body/title."
387+
)
388+
return True
389+
390+
# Check commit message
391+
if event_name == "push":
392+
commit_msg = (event.get("head_commit", {}).get("message") or "").lower()
393+
if tag in commit_msg:
394+
print( # noqa: T201
395+
"[is_full_ci_test] Detected @full_test in commit message."
396+
)
397+
return True
398+
399+
print("[is_full_ci_test] @full_test not found.") # noqa: T201
400+
return False

tests/integration/lit.cfg

Lines changed: 0 additions & 31 deletions
This file was deleted.

tests/integration/lit.cfg.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import os
2+
from typing import Any
3+
4+
import lit.formats
5+
6+
config: Any
7+
lit_config: Any
8+
9+
config.name = "html2pdf4doc Python API integration tests"
10+
config.test_format = lit.formats.ShTest("0")
11+
12+
current_dir = os.getcwd()
13+
14+
html2pdf_exec = lit_config.params["HTML2PDF4DOC_EXEC"]
15+
assert html2pdf_exec
16+
17+
config.substitutions.append(("%project_root", current_dir))
18+
config.substitutions.append(("%html2pdf", html2pdf_exec))
19+
20+
config.substitutions.append(
21+
(
22+
"%check_exists",
23+
'python "{}/tests/integration/check_exists.py"'.format(current_dir),
24+
)
25+
)
26+
config.substitutions.append(
27+
(
28+
"%expect_exit",
29+
'python "{}/tests/integration/expect_exit.py"'.format(current_dir),
30+
)
31+
)
32+
33+
config.suffixes = [".itest", ".c"]
34+
35+
config.is_windows = lit_config.isWindows
36+
if not lit_config.isWindows:
37+
config.available_features.add("PLATFORM_IS_NOT_WINDOWS")
38+
39+
is_full_test = lit_config.params.get("HTML2PDF4DOC_FULL_TEST", False)
40+
if is_full_test:
41+
config.available_features.add("FULL_TEST")
42+
43+
# In Linux CI, $HOME is required for Chrome as it needs to access things in ~/.local
44+
config.environment["HOME"] = os.environ.get("HOME", "/tmp")
45+
46+
# In Windows CI, %ProgramW6432% is required for Selenium to properly detect browsers
47+
config.environment["ProgramW6432"] = os.environ.get("ProgramW6432", "")

0 commit comments

Comments
 (0)