def setUpClass(cls): """Class setup.""" for emulator_name in emulator_names: if emulator_name not in _emulators: _emulators[emulator_name] = start_cloud_emulator( emulator_name) atexit.register(_emulators[emulator_name].cleanup) if emulator_name == 'datastore': cls._context_generator = ndb_init.context() cls._context_generator.__enter__() super(Wrapped, cls).setUpClass()
def run_testcase_and_return_result_in_queue(crash_queue, thread_index, file_path, gestures, env_copy, upload_output=False): """Run a single testcase and return crash results in the crash queue.""" # Since this is running in its own process, initialize the log handler again. # This is needed for Windows where instances are not shared across child # processes. See: # https://stackoverflow.com/questions/34724643/python-logging-with-multiprocessing-root-logger-different-in-windows logs.configure('run_testcase', { 'testcase_path': file_path, }) # Also reinitialize NDB context for the same reason as above. with ndb_init.context(): _do_run_testcase_and_return_result_in_queue( crash_queue, thread_index, file_path, gestures, env_copy, upload_output=upload_output)
logs.configure('run') # Python buffering can otherwise cause exception logs in the child run_*.py # processes to be lost. environment.set_value('PYTHONUNBUFFERED', 1) # Create command strings to launch bot and heartbeat. base_directory = environment.get_startup_scripts_directory() log_directory = environment.get_value('LOG_DIR') bot_log = os.path.join(log_directory, 'bot.log') bot_script_path = os.path.join(base_directory, BOT_SCRIPT) bot_interpreter = shell.get_interpreter(bot_script_path) assert bot_interpreter bot_command = '%s %s' % (bot_interpreter, bot_script_path) heartbeat_script_path = os.path.join(base_directory, HEARTBEAT_SCRIPT) heartbeat_interpreter = shell.get_interpreter(heartbeat_script_path) assert heartbeat_interpreter heartbeat_command = '%s %s %s' % (heartbeat_interpreter, heartbeat_script_path, bot_log) run_loop(bot_command, heartbeat_command) logs.log('Exit run.py') if __name__ == '__main__': with ndb_init.context(): main()