Skip to content

Commit

Permalink
Add --ddtrace flag (#9124)
Browse files Browse the repository at this point in the history
* Add --ddtrace option to tests

* Fix rebase

* Disable for py2

* Update datadog_checks_dev/datadog_checks/dev/tooling/commands/test.py

Co-authored-by: Florian Veaux <[email protected]>

* Fix typo

Co-authored-by: Florian Veaux <[email protected]>
  • Loading branch information
coignetp and FlorianVeaux authored Apr 13, 2021
1 parent 8099e3f commit 4a91567
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
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,11 +6,11 @@

import click

from ..._env import E2E_PARENT_PYTHON, SKIP_ENVIRONMENT
from ..._env import DDTRACE_OPTIONS_LIST, E2E_PARENT_PYTHON, SKIP_ENVIRONMENT
from ...ci import get_ci_env_vars, running_on_ci
from ...fs import chdir, file_exists, remove_path
from ...subprocess import run_command
from ...utils import get_next
from ...utils import ON_WINDOWS, get_next
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 @@ -32,6 +32,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 @@ -58,6 +59,7 @@ def test(
bench,
latest_metrics,
e2e,
ddtrace,
coverage,
junit,
cov_missing,
Expand Down Expand Up @@ -137,6 +139,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 @@ -153,6 +162,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):
# 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 @@ -176,6 +194,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

0 comments on commit 4a91567

Please sign in to comment.