Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
20 changes: 10 additions & 10 deletions riotfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
Venv(
name="meta-testing",
pys=["3.10"],
command="pytest {cmdargs} --no-ddtrace tests/meta",
command="pytest {cmdargs} tests/meta",
env={
"DD_CIVISIBILITY_FLAKY_RETRY_ENABLED": "0",
},
Expand Down Expand Up @@ -475,7 +475,7 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
name="integration",
# Enabling coverage for integration tests breaks certain tests in CI
# Also, running two separate pytest sessions, the ``civisibility`` one with --no-ddtrace
command="pytest -vv --no-ddtrace --no-cov --ignore-glob='*civisibility*' {cmdargs} tests/integration/",
command="pytest -vv --no-cov --ignore-glob='*civisibility*' {cmdargs} tests/integration/",
pkgs={"msgpack": [latest], "coverage": latest, "pytest-randomly": latest},
pys=select_pys(),
venvs=[
Expand All @@ -497,7 +497,7 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
name="integration-civisibility",
# Enabling coverage for integration tests breaks certain tests in CI
# Also, running two separate pytest sessions, the ``civisibility`` one with --no-ddtrace
command="pytest --no-cov --no-ddtrace {cmdargs} tests/integration/test_integration_civisibility.py",
command="pytest --no-cov {cmdargs} tests/integration/test_integration_civisibility.py",
Comment thread
gnufede marked this conversation as resolved.
pkgs={"msgpack": [latest], "coverage": latest, "pytest-randomly": latest},
pys=select_pys(),
venvs=[
Expand Down Expand Up @@ -2068,7 +2068,7 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
),
Venv(
name="unittest",
command="pytest --no-ddtrace {cmdargs} tests/contrib/unittest/",
command="pytest {cmdargs} tests/contrib/unittest/",
pkgs={
"msgpack": latest,
"pytest-randomly": latest,
Expand All @@ -2084,7 +2084,7 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
),
Venv(
name="asynctest",
command="pytest --no-ddtrace {cmdargs} tests/contrib/asynctest/",
command="pytest {cmdargs} tests/contrib/asynctest/",
pkgs={
"pytest-randomly": latest,
},
Expand All @@ -2105,7 +2105,7 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
),
Venv(
name="pytest_bdd",
command="pytest --no-ddtrace {cmdargs} tests/contrib/pytest_bdd/",
command="pytest {cmdargs} tests/contrib/pytest_bdd/",
pkgs={
"msgpack": latest,
"more_itertools": "<8.11.0",
Expand Down Expand Up @@ -2140,7 +2140,7 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
Venv(
name="pytest_benchmark",
pys=select_pys(),
command="pytest {cmdargs} --no-ddtrace --no-cov tests/contrib/pytest_benchmark/",
command="pytest {cmdargs} --no-cov tests/contrib/pytest_benchmark/",
pkgs={
"msgpack": latest,
"pytest-randomly": latest,
Expand All @@ -2161,7 +2161,7 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
Venv(
name="pytest:flaky",
pys=select_pys(),
command="pytest {cmdargs} --no-ddtrace --no-cov -p no:flaky tests/contrib/pytest_flaky/",
command="pytest {cmdargs} --no-cov -p no:flaky tests/contrib/pytest_flaky/",
pkgs={
"flaky": latest,
"pytest-randomly": latest,
Expand Down Expand Up @@ -3358,7 +3358,7 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
),
Venv(
name="aws_lambda",
command="pytest --no-ddtrace {cmdargs} tests/contrib/aws_lambda",
command="pytest {cmdargs} tests/contrib/aws_lambda",
pys=select_pys(min_version="3.9", max_version="3.13"),
pkgs={
"boto3": latest,
Expand Down Expand Up @@ -3874,7 +3874,7 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
"selenium": "~=4.0",
"webdriver-manager": latest,
},
command="pytest --no-cov {cmdargs} -c /dev/null --no-ddtrace tests/contrib/selenium",
command="pytest --no-cov {cmdargs} -c /dev/null tests/contrib/selenium",
env={
"DD_AGENT_PORT": "9126",
},
Expand Down
30 changes: 27 additions & 3 deletions tests/integration/test_integration_civisibility.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from unittest import mock

import mock
import pytest

from ddtrace.internal.ci_visibility import CIVisibility
Expand All @@ -18,6 +18,31 @@
AGENT_VERSION = os.environ.get("AGENT_VERSION")


@pytest.fixture(autouse=True)
def _isolate_from_outer_session(monkeypatch):
"""Strip DD_* env vars and suspend CIVisibility so each test starts with a clean slate.

When the outer pytest session runs with --ddtrace in CI, DD_API_KEY and other DD_* vars
are present in the process environment. Tests asserting on specific env conditions (e.g.
missing API key) must not see those vars. Each test sets its own DD_* vars explicitly via
override_env(), so stripping them all here is safe.

The CIVisibility suspension is belt-and-suspenders for the old plugin path where a
pre-existing singleton makes enable() return early.
"""
for key in list(os.environ):
if key.startswith(("DD_", "_CI_DD_")):
monkeypatch.delenv(key, raising=False)

suspended = CIVisibility._suspend()
try:
yield
finally:
if CIVisibility.enabled:
CIVisibility.disable()
CIVisibility._resume(suspended)


@pytest.fixture(autouse=True, scope="module")
def _dummy_check_enabled_features():
"""By default, assume that _check_enabled_features() returns an ITR-disabled response.
Expand Down Expand Up @@ -77,8 +102,7 @@ def test_civisibility_intake_with_apikey():
@pytest.mark.subprocess()
def test_civisibility_intake_payloads():
import gzip

import mock
from unittest import mock

from ddtrace.internal.ci_visibility.constants import COVERAGE_TAG_NAME
from ddtrace.internal.ci_visibility.recorder import CIVisibilityWriter
Expand Down
Loading