Skip to content

Issue #1201 capture output example tests#1203

Merged
JoerivanEngelen merged 4 commits intomasterfrom
issue_#1201_capture_output_example_tests
Sep 10, 2024
Merged

Issue #1201 capture output example tests#1203
JoerivanEngelen merged 4 commits intomasterfrom
issue_#1201_capture_output_example_tests

Conversation

@JoerivanEngelen
Copy link
Copy Markdown
Contributor

@JoerivanEngelen JoerivanEngelen commented Sep 9, 2024

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

  • Links to correct issue
  • Update changelog, if changes affect users
  • PR title starts with Issue #nr, e.g. Issue #737
  • Unit tests were added
  • If feature added: Added/extended example

@JoerivanEngelen JoerivanEngelen force-pushed the issue_#1201_capture_output_example_tests branch from 2ae3418 to 7667a30 Compare September 10, 2024 12:22
@JoerivanEngelen JoerivanEngelen added this pull request to the merge queue Sep 10, 2024
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 10, 2024
@JoerivanEngelen JoerivanEngelen merged commit d327617 into master Sep 10, 2024
@JoerivanEngelen JoerivanEngelen deleted the issue_#1201_capture_output_example_tests branch September 10, 2024 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Capture output test examples

2 participants