class WorkerProtocol(AMP): """ The worker-side trial distributed protocol. """ def __init__(self, forceGarbageCollection=False): self._loader = TestLoader() self._result = WorkerReporter(self) self._forceGarbageCollection = forceGarbageCollection def run(self, testCase): """ Run a test case by name. """ case = self._loader.loadByName(testCase) suite = TrialSuite([case], self._forceGarbageCollection) suite.run(self._result) return {'success': True} workercommands.Run.responder(run) def start(self, directory): """ Set up the worker, moving into given directory for tests to run in them. """ os.chdir(directory) return {'success': True} workercommands.Start.responder(start)
def _load_tests(name): """ Find all the tests under ``name``. :param str name: The fully-qualified Python name of an object. :return: A ``TestSuite`` or ``TestCase`` containing all the tests. """ loader = TestLoader() return loader.loadByName(name, recurse=True)
def get_tests_for(python_name): """ Find all tests for the given ``python_name``. :param python_name: Either directory in ``REPOSITORY`` or a Python FQPN importable from ``REPOSITORY``. :return: PSet of test names. """ def _extract_ids(t): if isinstance(t, TestSuite): result = pset() for sub_tests in t: result = result | _extract_ids(sub_tests) return result else: return pset([t.id()]) loader = TestLoader() tests = loader.loadByName(python_name, recurse=True) return _extract_ids(tests)
def runtests(root_dir='pyofwave'): runner = TrialRunner(TreeReporter) loader = TestLoader() failures = runner.run(loader.loadByName(root_dir, recurse=True)) sys.exit(failures)