Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
sys.argv[1:] = unparsed_args
# By default, pause before exiting
if not args.no_pause:
atexit.register(lambda: not multiprocessing.current_process().name.startswith("PoolWorker-") and
raw_input("Press Enter to exit ..."))
print("Testing", full_version() + "\n")
# Additional setup normally done by green.cmdline.main()
if has_green:
green_args = green.config.parseArguments()
green_args = green.config.mergeConfig(green_args)
if green_args.shouldExit:
sys.exit(green_args.exitCode)
green.suite.GreenTestSuite.args = green_args
if green_args.debug:
green.output.debug_level = green_args.debug
total_tests = total_skipped = total_failures = total_errors = total_passing = 0
def accumulate_results(r):
global total_tests, total_skipped, total_failures, total_errors, total_passing
total_tests += r.testsRun
total_skipped += len(r.skipped)
total_failures += len(r.failures)
total_errors += len(r.errors)
if has_green:
total_passing += len(r.passing)
timer = timeit.default_timer
start_time = time.time() if has_green else timer()
debug("Loaded config file(s): {}".format(
', '.join(config.files_loaded)))
# 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()))
def __init__(self, tests=(), args=None):
# You should either set GreenTestSuite.args before instantiation, or
# pass args into __init__
self._removed_tests = 0
self.allow_stdout = default_args.allow_stdout
self.full_test_pattern = 'test' + default_args.test_pattern
self.customize(args)
super(GreenTestSuite, self).__init__(tests)
if args.shouldExit:
return args.exitCode
# Clear out all the passed-in-options just in case someone tries to run a
# test that assumes sys.argv is clean. I can't guess at the script name
# that they want, though, so we'll just leave ours.
sys.argv = sys.argv[:1]
# Set up our various main objects
from green.loader import GreenTestLoader, getCompletions
from green.runner import run
from green.output import GreenStream, debug
import green.output
from green.suite import GreenTestSuite
GreenTestSuite.args = args
if args.debug:
green.output.debug_level = args.debug
stream = GreenStream(sys.stdout, disable_windows=args.disable_windows)
# Location of shell completion file
if args.completion_file:
print(os.path.join(os.path.dirname(__file__), 'shell_completion.sh'))
return 0
# Argument-completion for bash and zsh (for test-target completion)
if args.completions:
print(getCompletions(args.targets))
return 0
def discover(self, current_path, file_pattern='test*.py',
top_level_dir=None):
"""
I take a path to a directory and discover all the tests inside files
matching file_pattern.
If path is not a readable directory, I raise an ImportError.
If I don't find anything, I return None. Otherwise I return a
GreenTestSuite
"""
current_abspath = os.path.abspath(current_path)
if not os.path.isdir(current_abspath):
raise ImportError(
"'{}' is not a directory".format(str(current_path)))
suite = GreenTestSuite()
try:
for file_or_dir_name in sorted(os.listdir(current_abspath)):
path = os.path.join(current_abspath, file_or_dir_name)
# Recurse into directories, attempting to skip virtual environments
bin_activate = os.path.join(path, 'bin', 'activate')
if os.path.isdir(path) and not os.path.isfile(bin_activate):
# Don't follow symlinks
if os.path.islink(path):
continue
# Don't recurse into directories that couldn't be a package name
if not python_dir_pattern.match(file_or_dir_name):
continue
subdir_suite = self.discover(
path, file_pattern=file_pattern,
top_level_dir=top_level_dir or current_path