refactor code from run_tests.py into Python module

Good point. But sometimes I use those commented print statements to trace issues so I will keep it for now.