Skip to content

Commit d327617

Browse files
Issue #1201 capture output example tests (#1203)
Fixes #1201 # Description Print stderr and stdout message when example in ``test_examples.py`` fails. It will print a message like: ``` @pytest.mark.parametrize("example", get_examples()) def test_example(example): result = subprocess.run([sys.executable, example], capture_output=True) if result.returncode != 0: > raise RuntimeError( f"Example failed to run with returncode: {result.returncode} \n\n" f"stdout: {result.stdout.decode()} \n\n" f"stderr: {result.stderr.decode()} \n\n" ) E RuntimeError: Example failed to run with returncode: 1 E E stdout: E E stderr: Unzipping contents of 'C:\Users\Herman\AppData\Local\imod\imod\Cache\hondsrug-simulation.zip' to 'C:\Users\Herman\AppData\Local\Temp\tmpkhwjabqu\hondsrug_saved' E Traceback (most recent call last): E File "c:\src\imod-python\examples\mf6\hondsrug_partitioning.py", line 52, in <module> E raise ValueError("Some failure") E ValueError: Some failure ``` # Checklist - [x] Links to correct issue - [ ] Update changelog, if changes affect users - [x] PR title starts with ``Issue #nr``, e.g. ``Issue #737`` - [ ] Unit tests were added - [ ] **If feature added**: Added/extended example
1 parent 434e534 commit d327617

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

imod/tests/test_examples.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,10 @@ def get_examples():
1919
@pytest.mark.example
2020
@pytest.mark.parametrize("example", get_examples())
2121
def test_example(example):
22-
subprocess.run([sys.executable, example], check=True)
22+
result = subprocess.run([sys.executable, example], capture_output=True)
23+
if result.returncode != 0:
24+
raise RuntimeError(
25+
f"Example failed to run with returncode: {result.returncode} \n\n"
26+
f"stdout: {result.stdout.decode()} \n\n"
27+
f"stderr: {result.stderr.decode()} \n\n"
28+
)

0 commit comments

Comments
 (0)