def test_new_check_test(): check_path = os.path.join(CORE_ROOT, 'my_check') try: run_command( [sys.executable, '-m', 'datadog_checks.dev', 'create', '-q', '-l', CORE_ROOT, 'my-check'], capture=True, check=True ) run_command( [sys.executable, '-m', 'pip', 'install', check_path], capture=True, check=True ) with chdir(check_path): run_command([sys.executable, '-m', 'pytest'], capture=True, check=True) run_command( [sys.executable, '-m', 'pip', 'uninstall', '-y', 'my-check'], capture=True, check=True ) finally: remove_path(check_path)
def test_new_check_test(integration_type, installable): check_path = os.path.join(CORE_ROOT, 'my_check') try: run_command( [ sys.executable, '-m', 'datadog_checks.dev', 'create', '--type', integration_type, '--quiet', '--location', CORE_ROOT, 'My Check', ], capture=True, check=True, ) if installable: run_command([sys.executable, '-m', 'pip', 'install', check_path], capture=True, check=True) with chdir(check_path): ignored_env_vars = [TESTING_PLUGIN, 'PYTEST_ADDOPTS'] ignored_env_vars.extend(ev for ev in os.environ if ev.startswith(E2E_PREFIX)) with EnvVars(ignore=ignored_env_vars): run_command([sys.executable, '-m', 'pytest'], capture=True, check=True) # We only run style checks on the generated integration. Running the entire test suite would result in tox # creating Python environments, which would be too slow with little benefits. result = run_command([ sys.executable, '-m', 'datadog_checks.dev', 'test', '-s', 'my_check' ], capture=True, check=True) # `ddev test` will not fail if the provided check name doesn't correspond to an existing integration. # Instead, it will log a message. So we test for that message to verify style checks ran at all. assert 'Nothing to test!' not in result.stdout result = run_command([ sys.executable, '-m', 'pip', 'uninstall', '-y', 'datadog-my-check' ], capture=True, check=True) # `pip uninstall` is idempotent, so it will not fail if `check_package_name` is incorrect (i.e. the package # could not be found). Instead, it will log a warning, so we test for that warning to verify the package was # successfully uninstalled. # See: https://github.com/pypa/pip/issues/3016 assert 'WARNING: Skipping' not in result.stdout finally: remove_path(check_path)
def test_new_check_test(): check_path = os.path.join(CORE_ROOT, 'my_check') try: run_command( [ sys.executable, '-m', 'datadog_checks.dev', 'create', '-q', '-l', CORE_ROOT, 'my-check' ], capture=True, check=True, ) run_command([sys.executable, '-m', 'pip', 'install', check_path], capture=True, check=True) with chdir(check_path): ignored_env_vars = [TESTING_PLUGIN] ignored_env_vars.extend(ev for ev in os.environ if ev.startswith(E2E_PREFIX)) with EnvVars(ignore=ignored_env_vars): run_command([sys.executable, '-m', 'pytest'], capture=True, check=True) run_command( [sys.executable, '-m', 'pip', 'uninstall', '-y', 'my-check'], capture=True, check=True) finally: remove_path(check_path)