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