Skip to content
Draft
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
2 changes: 1 addition & 1 deletion ddtrace/testing/internal/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ def get_git_tags_from_dd_variables(env: t.MutableMapping[str, str]) -> t.Dict[st
branch = None

tags: t.Dict[str, t.Optional[str]] = {
GitTag.REPOSITORY_URL: env.get("DD_GIT_REPOSITORY_URL"),
GitTag.REPOSITORY_URL: env.get("_CI_DD_GIT_REPOSITORY_URL") or env.get("DD_GIT_REPOSITORY_URL"),
GitTag.COMMIT_SHA: env.get("DD_GIT_COMMIT_SHA"),
GitTag.BRANCH: branch,
GitTag.TAG: tag,
Expand Down
5 changes: 5 additions & 0 deletions ddtrace/testing/internal/pytest/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ def __init__(self, session_manager: SessionManager) -> None:
# during tests are captured by us (and not sent to the APM agent, for instance).
self.enable_ddtrace_trace_filter = True

# EXCEPTION: When testing ddtrace itself, we don't want to interfere with the normal operation of the tracer,
# and want ddtrace spans to be entirely independent from the test spans.
if asbool(os.environ.get("_DD_CIVISIBILITY_USE_CI_CONTEXT_PROVIDER")):
self.enable_ddtrace_trace_filter = False

self.enable_all_ddtrace_integrations = False
self.reports_by_nodeid: t.Dict[str, _ReportGroup] = defaultdict(lambda: {})
self.excinfo_by_report: t.Dict[pytest.TestReport, t.Optional[pytest.ExceptionInfo[t.Any]]] = {}
Expand Down
15 changes: 15 additions & 0 deletions ddtrace/testing/internal/session_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def __init__(self, session: TestSession) -> None:
)
self.settings = self.api_client.get_settings()
self.override_settings_with_env_vars()
self.show_settings()

self.known_tests = self.api_client.get_known_tests() if self.settings.known_tests_enabled else set()
self.test_properties = (
Expand Down Expand Up @@ -340,6 +341,20 @@ def override_settings_with_env_vars(self) -> None:
log.debug("TIA code coverage collection is enabled by environment variable")
self.settings.coverage_enabled = True

def show_settings(self) -> None:
log.info("Service: %s (env: %s)", self.service, self.env)
log.info(
"Test Optimization settings: Test Impact Analysis: %s, test skipping: %s, coverage collection: %s",
self.settings.itr_enabled,
self.settings.skipping_enabled,
self.settings.coverage_enabled,
)
log.info(
"Test Optimization settings: Early Flake Detection enabled: %s", self.settings.early_flake_detection.enabled
)
log.info("Test Optimization settings: Known Tests enabled: %s", self.settings.known_tests_enabled)
log.info("Test Optimization settings: Auto Test Retries enabled: %s", self.settings.auto_test_retries.enabled)


def _get_service_name_from_git_repo(env_tags: t.Dict[str, str]) -> t.Optional[str]:
repo_name = env_tags.get(GitTag.REPOSITORY_URL)
Expand Down
4 changes: 4 additions & 0 deletions ddtrace/testing/internal/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ def _send_events(self, events: t.List[Event]) -> None:
send_gzip=True,
)

self.connector.close()

TelemetryAPI.get().record_event_payload(
endpoint="test_cycle",
payload_size=len(pack),
Expand Down Expand Up @@ -223,6 +225,8 @@ def _send_events(self, events: t.List[Event]) -> None:

result = self.connector.post_files("/api/v2/citestcov", files=files, send_gzip=True)

self.connector.close()

TelemetryAPI.get().record_event_payload(
endpoint="code_coverage",
payload_size=len(pack),
Expand Down
20 changes: 20 additions & 0 deletions riotfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
"DD_PATCH_MODULES": "unittest:false",
"CMAKE_BUILD_PARALLEL_LEVEL": "12",
"CARGO_BUILD_JOBS": "12",
"_CI_DD_GIT_REPOSITORY_URL": "http://github.com/test-org/test-repo.git",
"DD_PYTEST_USE_NEW_PLUGIN": "true",
},
venvs=[
Venv(
Expand Down Expand Up @@ -1225,6 +1227,9 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
# DEV: Breaking change made in 2.1.0 release
"markupsafe": "<2.0",
},
env={
"DD_PYTEST_USE_NEW_PLUGIN": "false", # env uses pytest <= 7.2.0
},
venvs=[
Venv(pys=["3.9"], pkgs={"exceptiongroup": latest}),
],
Expand Down Expand Up @@ -1794,6 +1799,7 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
},
env={
"DD_AGENT_PORT": "9126",
"DD_PYTEST_USE_NEW_PLUGIN": "false", # env has tests for the old pytest plugin
},
venvs=[
Venv(
Expand Down Expand Up @@ -1851,6 +1857,7 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
env={
"DD_AGENT_PORT": "9126",
"DD_PYTEST_USE_NEW_PLUGIN": "true",
"_DD_CIVISIBILITY_USE_CI_CONTEXT_PROVIDER": "0",
},
venvs=[
Venv(
Expand Down Expand Up @@ -1904,6 +1911,9 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
pkgs={
"pytest-randomly": latest,
},
env={
"DD_PYTEST_USE_NEW_PLUGIN": "false", # env uses pytest <= 7.2.0
},
venvs=[
Venv(
pys="3.9",
Expand All @@ -1930,6 +1940,9 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
">=6.0,<6.1",
],
},
env={
"DD_PYTEST_USE_NEW_PLUGIN": "false", # env has tests for the old pytest plugin
},
venvs=[
Venv(
pys="3.9",
Expand Down Expand Up @@ -1960,6 +1973,9 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
"msgpack": latest,
"pytest-randomly": latest,
},
env={
"DD_PYTEST_USE_NEW_PLUGIN": "false", # env has tests for the old pytest plugin
},
venvs=[
Venv(
pkgs={
Expand All @@ -1978,6 +1994,9 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
"flaky": latest,
"pytest-randomly": latest,
},
env={
"DD_PYTEST_USE_NEW_PLUGIN": "false", # env has tests for the old pytest plugin
},
),
Venv(
name="grpc",
Expand Down Expand Up @@ -3220,6 +3239,7 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
},
env={
"DD_AGENT_PORT": "9126",
"DD_PYTEST_USE_NEW_PLUGIN": "false", # env has tests for the old pytest plugin
},
venvs=[
Venv(
Expand Down
20 changes: 10 additions & 10 deletions tests/tracer/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,20 +338,20 @@ def test_logger_does_not_add_handler_when_configured():


def test_logger_log_level_from_env(monkeypatch):
monkeypatch.setenv("_DD_TESTING_DEBUG_LOG_LEVEL", "DEBUG")
monkeypatch.setenv("_DD_TESTING_WARNING_LOG_LEVEL", "WARNING")
monkeypatch.setenv("_DD_EXAMPLE_DEBUG_LOG_LEVEL", "DEBUG")
monkeypatch.setenv("_DD_EXAMPLE_WARNING_LOG_LEVEL", "WARNING")
monkeypatch.setenv("_DD_PACKAGE_WITH_UNDERSCORE_SUBMODULE_LOG_LEVEL", "ERROR")

import ddtrace.internal.logger as dd_logger

with mock.patch.object(dd_logger, "LOG_LEVEL_TRIE", dd_logger.LoggerPrefix.build_trie()):
assert get_logger("ddtrace.testing.debug.foo.bar").level == logging.DEBUG
assert get_logger("ddtrace.testing.debug.foo").level == logging.DEBUG
assert get_logger("ddtrace.testing.debug").level == logging.DEBUG
assert get_logger("ddtrace.testing").level < logging.DEBUG

assert get_logger("ddtrace.testing.warning.foo.bar").level == logging.WARNING
assert get_logger("ddtrace.testing.warning.foo").level == logging.WARNING
assert get_logger("ddtrace.testing.warning").level == logging.WARNING
assert get_logger("ddtrace.example.debug.foo.bar").level == logging.DEBUG
assert get_logger("ddtrace.example.debug.foo").level == logging.DEBUG
assert get_logger("ddtrace.example.debug").level == logging.DEBUG
assert get_logger("ddtrace.example").level < logging.DEBUG

assert get_logger("ddtrace.example.warning.foo.bar").level == logging.WARNING
assert get_logger("ddtrace.example.warning.foo").level == logging.WARNING
assert get_logger("ddtrace.example.warning").level == logging.WARNING

assert get_logger("ddtrace.package_with_underscore.submodule").level == logging.ERROR
Loading