The following code is used to execute doctests in a Google App Engine app. How would you do this for tests written as unit test asserts rather than as doctests?
#The solution and tests are untrusted code passed in to the GAE app.
solution = 'b=5'
unittest = 'assertEqual(b, 5)'
#Here is the doctest version as a reference.
solution = 'b=5'
doctest = '>>> b \n 5'
#Compile and exec the untrusted solution provided by the user.
compiled = compile(solution, 'submitted code', 'exec')
sandbox = {}
exec compiled in sandbox
#Compile and exec each of the doctests
test_cases = doctest.DocTestParser().get_examples(doctest)
for test in test_cases:
if not test.want:
exec test.source in sandbox