I am writing problem solution checker for contest system like Codeforces. Here is check_test function for Python submissions:
check_test
class PythonTestChecker