I'm looking for a way to customize the output of python unittests. So far, I think my best chance is using pytest hooks to achieve my goal.
Regardless, I've tried to implement something myself and have been fairly successful in navigating test classes with Python's AST. I've used it to find all test classes, functions and nodes executing "assertEqual" or similar expressions for testing.
Now the next step would be to load the tests dynamically, execute them, redirect the output to a file and then parse this file to obtain the actual test results, so I can combine both the information from the AST and from the actual execution. But I'm really stuck here, I've tried several methods, but I'm unable to load the testcase in a TestSuite, which I would then pass to a TextTestRunner, which would write the output to a file.
I've tried the following code:
"~/dev/python/myproject/tests/mytestclass.py": full path to the test class I want to load "~/dev/python/custom_tests/custom_tests/parser.py": full path to the file that shall load the test class given above
I add the path to the project ("~/dev/python/myproject/") to my path
sys.path.insert(0, self.path)
I try to find the module "tests"
f, pathname, desc = imp.find_module("tests") module = imp.load_module("tests", f, pathname, desc)
I try to load mytestclass
f, pathname, desc = imp.find_module("test_status_code", module.__path__) test = imp.load_module("mytestclass", f, pathname, desc)
This works so far, but how can I add this to a TestSuite?