#23930: Context manager for capturing output
-----------------------------------+--------------------
Reporter: wrwrwr | Owner: nobody
Type: New feature | Status: new
Component: Testing framework | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------
I've recently something like this (for #23929, where the output is
generated by a signal handler):
{{{#!python
@contextmanager
def capture_stdout():
"""
Captures the ``sys.stdout`` stream, making anything written to it
available in the stream returned as the manager's context.
For example:
with capture_stdout() as out:
# Print something.
self.assertIn("something", out.getvalue())
"""
old_stdout = sys.stdout
sys.stdout = out = StringIO()
try:
yield out
finally:
sys.stdout = old_stdout
}}}
Would it be better to make it public, leave it buried for the test only or
don't mind testing the output it such cases at all?
--
Ticket URL: <https://code.djangoproject.com/ticket/23930>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/049.ca17f8053262cfcaa163fc3ab4062880%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.