def setup_site_and_switch_user(): if testlib.is_running_as_site_user(): return # This is executed as site user. Nothing to be done. sys.stdout.write("===============================================\n") sys.stdout.write("Setting up site '%s'\n" % testlib.site_id()) sys.stdout.write("===============================================\n") site = _get_site_object() cleanup_pattern = os.environ.get("CLEANUP_OLD") if cleanup_pattern: site.cleanup_old_sites(cleanup_pattern) site.cleanup_if_wrong_version() site.create() #site.open_livestatus_tcp() site.start() site.prepare_for_tests() sys.stdout.write("===============================================\n") sys.stdout.write("Switching to site context\n") sys.stdout.write("===============================================\n") sys.stdout.flush() exit_code = site.switch_to_site_user() sys.exit(exit_code)
def pytest_cmdline_main(config): """There are 2 environments for testing: * A real Check_MK site environment (e.g. integration tests) * Python virtual environment (e.g. for unit tests) Depending on the selected "type" marker the environment is ensured or switched here.""" if not config.getoption("-T"): return # missing option is handled later context = test_types[config.getoption("-T")] if context == EXECUTE_IN_SITE and not testlib.is_running_as_site_user(): raise Exception() else: verify_virtualenv()
def cleanup_cmk(): yield if testlib.is_running_as_site_user(): return import cmk.utils.paths if "pytest_cmk_" not in cmk.utils.paths.tmp_dir: return try: shutil.rmtree(cmk.utils.paths.tmp_dir) except OSError as exc: if exc.errno != errno.ENOENT: raise # re-raise exception