Skip to content

Commit 17426e5

Browse files
Add verbose option
1 parent cd16c84 commit 17426e5

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

_tests/conftest.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""Pytest options for docs code-block compilation tests."""
2+
3+
4+
def pytest_addoption(parser):
5+
"""Register project-local pytest CLI flags."""
6+
parser.addoption(
7+
"--block-verbose",
8+
action="store_true",
9+
default=False,
10+
help=(
11+
"Include failing markdown block id and full block source "
12+
"in assertion output for code-block tests."
13+
),
14+
)

_tests/test_code_blocks.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@
7474
)
7575

7676

77+
def _verbose_context(request, code: str) -> str:
78+
"""Return extra failure details when --block-verbose is enabled."""
79+
if not request.config.getoption("--block-verbose"):
80+
return ""
81+
block_id = getattr(getattr(request.node, "callspec", None), "id", "unknown-block")
82+
return (
83+
f"\n--- failing block: {block_id} ---\n"
84+
f"{code}\n"
85+
"--- end block ---\n"
86+
)
87+
88+
7789
# ---------------------------------------------------------------------------
7890
# Block collection
7991
# ---------------------------------------------------------------------------
@@ -174,7 +186,7 @@ def _print_str(ptr, length):
174186
# ---------------------------------------------------------------------------
175187

176188
@pytest.mark.parametrize('code', _collect_blocks())
177-
def test_block(code, tmp_path):
189+
def test_block(code, tmp_path, request):
178190
"""
179191
Each executable code block in the docs must:
180192
1. Compile to WAT text without error.
@@ -192,6 +204,7 @@ def test_block(code, tmp_path):
192204
capture_output=True, text=True, timeout=COMPILE_TIMEOUT,
193205
)
194206
assert result.returncode == 0, (
207+
_verbose_context(request, code) +
195208
f'build-wasm-bundle failed (exit {result.returncode}):\n'
196209
f'{result.stderr.strip()}'
197210
)
@@ -208,6 +221,7 @@ def test_block(code, tmp_path):
208221
capture_output=True, timeout=ASSEMBLE_TIMEOUT,
209222
)
210223
assert result.returncode == 0, (
224+
_verbose_context(request, code) +
211225
f'wat2wasm failed (exit {result.returncode}):\n'
212226
f'{result.stderr.decode(errors="replace").strip()}'
213227
)
@@ -218,6 +232,7 @@ def test_block(code, tmp_path):
218232
capture_output=True, timeout=VALIDATE_TIMEOUT,
219233
)
220234
assert result.returncode == 0, (
235+
_verbose_context(request, code) +
221236
f'wasm-validate rejected the binary:\n'
222237
f'{result.stderr.decode(errors="replace").strip()}'
223238
)

0 commit comments

Comments
 (0)