Jaymon / testdata

Python module to make testing easier, it can generate random data like names and text, run commands, fetch urls, create files and directories, and more
MIT License
10 stars 0 forks source link

output capture module #10

Closed Jaymon closed 7 years ago

Jaymon commented 7 years ago

add a new module that when imported will capture stdout and stderr so you can use a context block to see what they say:

with output.capture() as s:
    # do something here that prints to stdout/stderr
    self.assertTrue("something" in s.stdout)

Something along the lines of that. The capturing mechanism can be transparent, so it basically will replace sys.stdout and sys.stderr with wrapper objects that will still print it to the screen but will also capture it so it can be inspected.

This module would have to be imported as close to the top of the module as possible to capture any other modules that do something like:

from sys import stdout

or anything similar, so you would want to import testdata.output as close to entrance into the script as possible.