I am trying to automate autograding with nbgrader. Usually the student writes a piece of code (like a variable or a function) in the autograded answer cell that the instructor uses (by referring to the variable or function) to write autograder tests.
But some times the input code from the autograded answer cell can be just a print(...) which outputs something to the screen (rather than a variable or function). In that case how is it possible to capture the printed output so that we can use it the next cell for writing autograder tests on it ?
The nbgrader docs include an example demonstrating how to patch the builtin function
printso you can capture and test printed output: