Respect pytest -s
flag, streaming stdout/stderr as the test runs
#200
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Checklist
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 setscapture=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:
andstderr:
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
andstderr
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
. ButContentTestItem
specifies arepr_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:
Let me know if you think there's a better way to implement this.