Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def main(test_module, exit = None, buffer = None):
import green.loader, green.runner
if buffer:
green_args.quiet_stdout = True
try:
suite = green.loader.GreenTestLoader().loadTestsFromModule(test_module) # new API (v2.9+)
except AttributeError:
suite = green.loader.loadFromModule(test_module) # legacy API
results = green.runner.run(suite, sys.stdout, green_args)
# Return the results in an object with a "result" attribute, same as unittest.main()
return collections.namedtuple("Tuple", "result")(results)
if type(test_labels) == tuple:
test_labels = list(test_labels)
else:
raise ValueError("test_labels should be a tuple of strings")
if not test_labels:
test_labels = ['.']
args = mergeConfig(Namespace())
if self.verbose != -1:
args.verbose = self.verbose
args.targets = test_labels
stream = GreenStream(sys.stdout)
suite = self.loader.loadTargets(args.targets)
if not suite:
suite = GreenTestSuite()
result = run(suite, stream, args)
# Django teardown
self.teardown_databases(django_db)
self.teardown_test_environment()
return self.suite_result(suite, result)
# Discover/Load the test suite
if testing:
test_suite = None
else: # pragma: no cover
loader = GreenTestLoader()
test_suite = loader.loadTargets(args.targets,
file_pattern=args.file_pattern)
# We didn't even load 0 tests...
if not test_suite:
debug(
"No test loading attempts succeeded. Created an empty test suite.")
test_suite = GreenTestSuite()
# Actually run the test_suite
result = run(test_suite, stream, args, testing)
# Generate a test report if required
if args.junit_report:
from green.junit import JUnitXML
adapter = JUnitXML()
with open(args.junit_report, "w") as report_file:
adapter.save_as(result, report_file)
return(int(not result.wasSuccessful()))