Files and random numbers.

Re: Files and random numbers.

by Mike McDowell -
Number of replies: 0
You could capture the output into a list then assess it with your test (this works per test in the test code), limiting the printed output:

# Capture stdout
import sys, io
old_stdout = sys.stdout
new_stdout = io.StringIO()
sys.stdout = new_stdout

# Now run the student methods/code while output is off

# Restore stdout when you're ready to allow output again
sys.stdout = old_stdout
output = new_stdout.getvalue()

# Split captured output into lines for analysis
lines = output.splitlines()

# Output the results or feedback from your examination of lines/output for your test