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 --ddtrace flag #9124

Merged
merged 6 commits into from
Apr 13, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
7 changes: 7 additions & 0 deletions datadog_checks_dev/datadog_checks/dev/_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@

from six import iteritems

DDTRACE_OPTIONS_LIST = [
'DD_TAGS',
'DD_TRACE*',
'DD_SERVICE',
'DD_AGENT_HOST',
'DD_ENV',
]
E2E_PREFIX = 'DDEV_E2E'
E2E_ENV_VAR_PREFIX = '{}_ENV_'.format(E2E_PREFIX)
E2E_SET_UP = '{}_UP'.format(E2E_PREFIX)
Expand Down
23 changes: 21 additions & 2 deletions datadog_checks_dev/datadog_checks/dev/tooling/commands/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

import click

from ..._env import E2E_PARENT_PYTHON, SKIP_ENVIRONMENT
from ..._env import DDTRACE_OPTIONS_LIST, E2E_PARENT_PYTHON, SKIP_ENVIRONMENT
from ...subprocess import run_command
from ...utils import chdir, file_exists, get_ci_env_vars, get_next, remove_path, running_on_ci
from ...utils import ON_WINDOWS, chdir, file_exists, get_ci_env_vars, get_next, remove_path, running_on_ci
from ..constants import get_root
from ..dependencies import read_check_base_dependencies
from ..testing import construct_pytest_options, fix_coverage_report, get_tox_envs, pytest_coverage_sources
Expand All @@ -30,6 +30,7 @@ def display_envs(check_envs):
@click.option('--bench', '-b', is_flag=True, help='Run only benchmarks')
@click.option('--latest-metrics', is_flag=True, help='Only verify support of new metrics')
@click.option('--e2e', is_flag=True, help='Run only end-to-end tests')
@click.option('--ddtrace', is_flag=True, help='Run tests using dd-trace-py')
@click.option('--cov', '-c', 'coverage', is_flag=True, help='Measure code coverage')
@click.option('--cov-missing', '-cm', is_flag=True, help='Show line numbers of statements that were not executed')
@click.option('--junit', '-j', 'junit', is_flag=True, help='Generate junit reports')
Expand All @@ -56,6 +57,7 @@ def test(
bench,
latest_metrics,
e2e,
ddtrace,
coverage,
junit,
cov_missing,
Expand Down Expand Up @@ -135,6 +137,13 @@ def test(
test_env_vars[E2E_PARENT_PYTHON] = sys.executable
test_env_vars['TOX_TESTENV_PASSENV'] += f' {E2E_PARENT_PYTHON}'

if ddtrace:
for env in DDTRACE_OPTIONS_LIST:
test_env_vars['TOX_TESTENV_PASSENV'] += f' {env}'
# Used for CI app product
test_env_vars['TOX_TESTENV_PASSENV'] += ' TF_BUILD BUILD* SYSTEM*'
test_env_vars['DD_SERVICE'] = os.getenv('DD_SERVICE', 'ddev-integrations')

org_name = ctx.obj['org']
org = ctx.obj['orgs'].get(org_name, {})
api_key = org.get('api_key') or ctx.obj['dd_api_key'] or os.getenv('DD_API_KEY')
Expand All @@ -151,6 +160,15 @@ def test(
echo_debug(f"No envs found for: `{check}`")
continue

ddtrace_check = ddtrace
if ddtrace and ON_WINDOWS and any('py2' in env for env in envs):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since all the environment are grouped in the tox command, the flag is disabled for the whole check if there is one windows-py2 env

# The pytest flag --ddtrace is not available for windows-py2 env.
# Removing it so it does not fail.
echo_warning(
'ddtrace flag is not available for windows-py2 environments ; disabling the flag for this check.'
)
ddtrace_check = False

# This is for ensuring proper spacing between output of multiple checks' tests.
# Basically this avoids printing a new line before the first check's tests.
output_separator = '\n' if tests_ran else ''
Expand All @@ -174,6 +192,7 @@ def test(
test_filter=test_filter,
pytest_args=pytest_args,
e2e=e2e,
ddtrace=ddtrace_check,
)
if coverage:
pytest_options = pytest_options.format(pytest_coverage_sources(check))
Expand Down
4 changes: 4 additions & 0 deletions datadog_checks_dev/datadog_checks/dev/tooling/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ def construct_pytest_options(
test_filter='',
pytest_args='',
e2e=False,
ddtrace=False,
):
# Prevent no verbosity
pytest_options = f'--verbosity={verbose or 1}'
Expand All @@ -236,6 +237,9 @@ def construct_pytest_options(
pytest_options += ' --run-latest-metrics'
marker = 'latest_metrics'

if ddtrace:
pytest_options += ' --ddtrace'

if junit:
test_group = 'e2e' if e2e else 'unit'
pytest_options += (
Expand Down