def run_tests(_driver): global driver driver = _driver logging.basicConfig(level=logging.INFO) webserver = SimpleWebServer() webserver.start() try: testLoader = unittest.TestLoader() testRunner = unittest.TextTestRunner() testRunner.run(testLoader.loadTestsFromTestCase(ApiExampleTest)) driver.quit() finally: webserver.stop()