Skip to content

Commit

Permalink
tests: Show captured stdout in test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
geigerzaehler committed Nov 16, 2024
1 parent 9a11373 commit 989aa45
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions test/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,23 @@

@contextmanager
def capture_stdout():
r"""Save stdout in a StringIO.
r"""Collect stdout in a StringIO while still outputting it.
>>> with capture_stdout() as output:
... print('spam')
...
spam
>>> output.getvalue()
'spam\n'
"""
org = sys.stdout
sys.stdout = StringIO()
buffer = StringIO()
sys.stdout = buffer
try:
yield sys.stdout
finally:
sys.stdout = org
sys.stdout.write(buffer.getvalue())


@contextmanager
Expand Down

0 comments on commit 989aa45

Please sign in to comment.