Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to skip environment creation for tests #5760

Merged
merged 2 commits into from
Feb 18, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions datadog_checks_dev/datadog_checks/dev/_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

E2E_FIXTURE_NAME = 'dd_environment'
TESTING_PLUGIN = 'DDEV_TESTING_PLUGIN'
SKIP_ENVIRONMENT = 'DDEV_SKIP_ENV'


def e2e_active():
Expand Down
14 changes: 14 additions & 0 deletions datadog_checks_dev/datadog_checks/dev/plugin/pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
AGENT_COLLECTOR_SEPARATOR,
E2E_FIXTURE_NAME,
E2E_PARENT_PYTHON,
SKIP_ENVIRONMENT,
TESTING_PLUGIN,
e2e_active,
e2e_testing,
Expand Down Expand Up @@ -130,6 +131,19 @@ def dd_environment_runner(request):
pytest.exit(message)


@pytest.fixture(scope='session', autouse=True)
def dd_environment_skipper(request):
# Skip the runner if the environment variable is specified
do_skip = os.getenv(SKIP_ENVIRONMENT) == 'true'
if not do_skip:
return
# Since the scope is `session` there should only ever be one definition
fixture_def = request._fixturemanager._arg2fixturedefs[E2E_FIXTURE_NAME][0]

# Make the underlying function a no-op
fixture_def.func = lambda: None
therve marked this conversation as resolved.
Show resolved Hide resolved


@pytest.fixture
def dd_agent_check(request, aggregator):
if not e2e_testing():
Expand Down
11 changes: 10 additions & 1 deletion datadog_checks_dev/datadog_checks/dev/tooling/commands/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import click

from ..._env import E2E_PARENT_PYTHON
from ..._env import E2E_PARENT_PYTHON, SKIP_ENVIRONMENT
from ...subprocess import run_command
from ...utils import chdir, file_exists, get_ci_env_vars, remove_path, running_on_ci
from ..constants import get_root
Expand Down Expand Up @@ -40,6 +40,7 @@ def display_envs(check_envs):
@click.option('--passenv', help='Additional environment variables to pass down')
@click.option('--changed', is_flag=True, help='Only test changed checks')
@click.option('--cov-keep', is_flag=True, help='Keep coverage reports')
@click.option('--skip-env', is_flag=True, help='Skip dd_environment start')
therve marked this conversation as resolved.
Show resolved Hide resolved
@click.option('--pytest-args', '-pa', help='Additional arguments to pytest')
@click.pass_context
def test(
Expand All @@ -61,6 +62,7 @@ def test(
passenv,
changed,
cov_keep,
skip_env,
pytest_args,
):
"""Run tests for Agent-based checks.
Expand Down Expand Up @@ -108,6 +110,13 @@ def test(
'DDEV_COV_MISSING': coverage_show_missing_lines,
}

if skip_env:
os.putenv(SKIP_ENVIRONMENT, 'true')
if passenv is None:
passenv = SKIP_ENVIRONMENT
else:
passenv += f' SKIP_ENVIRONMENT'
therve marked this conversation as resolved.
Show resolved Hide resolved

if passenv:
test_env_vars['TOX_TESTENV_PASSENV'] += f' {passenv}'

Expand Down