def test_recursive_discovery_python_unittest(self): temp_test = script.TemporaryScript( 'recursive_discovery_python_unittest.py', RECURSIVE_DISCOVERY_PYTHON_UNITTEST) temp_test.save() tests = safeloader.find_python_unittests(temp_test.path) expected = { 'BaseClass': [('test_maybe_replaced_by_child', { 'base-tag': None, 'base.tag': None }, []), ('test_basic', { 'base-tag': None, 'base.tag': None }, [])], 'Child': [('test_maybe_replaced_by_child', { 'child-tag': None, 'child.tag': None }, []), ('test_child', { 'child-tag': None, 'child.tag': None }, []), ('test_basic', { 'base-tag': None, 'base.tag': None }, [])] } self.assertEqual(expected, tests)
def resolve(reference): criteria_check = check_file(reference, reference) if criteria_check is not True: return criteria_check class_methods = find_python_unittests(reference) if class_methods: runnables = [] mod = os.path.relpath(reference) if mod.endswith('.py'): mod = mod[:-3] mod = mod.replace(os.path.sep, ".") for klass, meths in class_methods.items(): for (meth, tags) in meths: uri = '%s.%s.%s' % (mod, klass, meth) runnables.append( Runnable('python-unittest', uri=uri, tags=tags)) if runnables: return ReferenceResolution(reference, ReferenceResolutionResult.SUCCESS, runnables) return ReferenceResolution(reference, ReferenceResolutionResult.NOTFOUND)
def _find_python_unittests(test_path, disabled, subtests_filter): result = [] class_methods = safeloader.find_python_unittests(test_path) for klass, methods in class_methods.items(): if klass in disabled: continue if test_path.endswith(".py"): test_path = test_path[:-3] test_module_name = os.path.relpath(test_path) test_module_name = test_module_name.replace(os.path.sep, ".") candidates = [("%s.%s.%s" % (test_module_name, klass, method), tags) for (method, tags, _) in methods] if subtests_filter: result += [_ for _ in candidates if subtests_filter.search(_)] else: result += candidates return result
def _find_compat(module_path): """Used as compatibility for the :func:`python_resolver()` interface.""" return find_python_unittests(module_path), None