Hello i was wondering if it is possible and if so how? to do doctests or something similar from the mainline, instead of testing a function as is described in the doctest docs i.e.
"""
>>>
Hello World
"""
if __name__ == "__main__":
print "Hello"
import doctest
doctest.testmod()
This is part of being able to test students scripts against a docstring, i found this snipet of code that allows me to input both as strongs
import doctest
from doctest import DocTestRunner, DocTestParser
enter code here
def run_doctest(code, test):
import doctest
from doctest import DocTestRunner, DocTestParser
code = code + '\n__dtest=__parser.get_doctest(__test, globals(), "Crunchy Doctest", "crunchy", 0)\n__runner.run(__dtest)\n'
runner = DocTestRunner()
parser = DocTestParser()
exec code in {'__runner':runner, '__parser':parser, '__test':test}
that does more or less but it seems hardly ideal, an suggestions on either point