Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect pytest -s flag, streaming stdout/stderr as the test runs #200

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

jchorl
Copy link

@jchorl jchorl commented Aug 4, 2024

Checklist

  • Pull request details were added to HISTORY.rst

I took a crack at #199

Doing some research, it seems pytest already has a setting to dictate how to handle stdout/stderr: https://docs.pytest.org/en/latest/how-to/capture-stdout-stderr.html#setting-capturing-methods-or-disabling-capturing

I added support for -s (which sets capture=no). It bypasses capturing stdout/stderr, streaming them to the terminal in real-time. I did not attempt to implement the other options because they're more complex - capturing and streaming output simultaneously might require a multithreaded implementation. I couldn't find a great way to support it.

Note that this is incompatible with stdout: and stderr: tests (as there is no captured stdout/stderr to check). I wasn't sure where the best place to catch this incompatibility was.

At first, I de-registered the stdout and stderr ContentTestCollector altogether when -s is specified. But this just silently drops those tests - no good.

Then I moved to validating at test runtime in runtest. But ContentTestItem specifies a repr_failure message which didn't really describe this failure mode.

So then I moved to validating in the per-test-item constructor. This does work. I'm not sure if it's the best place.

I tried to add some tests to make sure this functions as expected. I also used variants of the following yaml to manually test:

- name: tee test
  command: bash -c "echo foo | tee test.file && sleep 3"
  files:
    - path: test.file
      contains:
        - foo
        - bar
  stdout:
    contains:
      - bar

Let me know if you think there's a better way to implement this.

@rhpvorderman
Copy link
Member

Thank you very much for this. I will look into this when I have the time. I am currently very busy.

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.

2 participants