Skip to content

Commit

Permalink
Merge branch '1.17' into backport-6569-to-1.17
Browse files Browse the repository at this point in the history
  • Loading branch information
mabdinur authored Aug 11, 2023
2 parents 296b410 + 59a0820 commit 657bb84
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 14 deletions.
1 change: 1 addition & 0 deletions tests/ci_visibility/test_ci_visibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ def test_git_client_worker_agentless(_do_request, git_repo):
DD_APPLICATION_KEY="banana",
DD_CIVISIBILITY_ITR_ENABLED="1",
DD_CIVISIBILITY_AGENTLESS_ENABLED="1",
DD_SITE="datadoghq.com",
)
):
ddtrace.internal.ci_visibility.recorder.ddconfig = ddtrace.settings.Config()
Expand Down
8 changes: 7 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,13 @@ def run_function_from_file(item, params=None):
pythonpath = os.getenv("PYTHONPATH", None)
base_path = os.path.dirname(os.path.dirname(__file__))
env["PYTHONPATH"] = os.pathsep.join((base_path, pythonpath)) if pythonpath is not None else base_path
env.update(marker.kwargs.get("env", {}))

for key, value in marker.kwargs.get("env", {}).items():
if value is None: # None means remove the variable
env.pop(key, None)
else:
env[key] = value

if params is not None:
env.update(params)

Expand Down
28 changes: 16 additions & 12 deletions tests/contrib/pytest/test_pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def pytest_configure(config):

def subprocess_run(self, *args):
"""Execute test script with test tracer."""
return self.testdir.runpytest_subprocess(*args)
with override_env(dict(DD_API_KEY="foobar.baz")):
return self.testdir.runpytest_subprocess(*args)

@pytest.mark.skipif(sys.version_info[0] == 2, reason="Triggers a bug with coverage, sqlite and Python 2")
def test_patch_all(self):
Expand Down Expand Up @@ -491,9 +492,6 @@ def test_fixture(ddspan):

def test_service_name_repository_name(self):
"""Test span's service name is set to repository name."""
self.monkeypatch.setenv("APPVEYOR", "true")
self.monkeypatch.setenv("APPVEYOR_REPO_PROVIDER", "github")
self.monkeypatch.setenv("APPVEYOR_REPO_NAME", "test-repository-name")
py_file = self.testdir.makepyfile(
"""
import os
Expand All @@ -503,7 +501,14 @@ def test_service(ddspan):
"""
)
file_name = os.path.basename(py_file.strpath)
rec = self.subprocess_run("--ddtrace", file_name)
with override_env(
{
"APPVEYOR": "true",
"APPVEYOR_REPO_PROVIDER": "github",
"APPVEYOR_REPO_NAME": "test-repository-name",
}
):
rec = self.subprocess_run("--ddtrace", file_name)
rec.assert_outcomes(passed=1)

def test_default_service_name(self):
Expand All @@ -524,7 +529,6 @@ def test_service(ddspan):

def test_dd_service_name(self):
"""Test dd service name."""
self.monkeypatch.setenv("DD_SERVICE", "mysvc")
if "DD_PYTEST_SERVICE" in os.environ:
self.monkeypatch.delenv("DD_PYTEST_SERVICE")

Expand All @@ -539,15 +543,12 @@ def test_service(ddspan):
"""
)
file_name = os.path.basename(py_file.strpath)
rec = self.subprocess_run("--ddtrace", file_name)
with override_env({"DD_SERVICE": "mysvc"}):
rec = self.subprocess_run("--ddtrace", file_name)
assert 0 == rec.ret

def test_dd_pytest_service_name(self):
"""Test integration service name."""
self.monkeypatch.setenv("DD_SERVICE", "mysvc")
self.monkeypatch.setenv("DD_PYTEST_SERVICE", "pymysvc")
self.monkeypatch.setenv("DD_PYTEST_OPERATION_NAME", "mytest")

py_file = self.testdir.makepyfile(
"""
import os
Expand All @@ -560,7 +561,10 @@ def test_service(ddspan):
"""
)
file_name = os.path.basename(py_file.strpath)
rec = self.subprocess_run("--ddtrace", file_name)
with override_env(
{"DD_SERVICE": "mysvc", "DD_PYTEST_SERVICE": "pymysvc", "DD_PYTEST_OPERATION_NAME": "mytest"}
):
rec = self.subprocess_run("--ddtrace", file_name)
assert 0 == rec.ret

def test_dd_origin_tag_propagated_to_every_span(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/profiling/test_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def test_disable_memory():


@pytest.mark.subprocess(
env=dict(DD_PROFILING_AGENTLESS="true", DD_API_KEY="foobar"),
env=dict(DD_PROFILING_AGENTLESS="true", DD_API_KEY="foobar", DD_SITE=None),
err=None,
)
def test_env_agentless():
Expand Down
4 changes: 4 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ def override_env(env):
# Copy the full original environment
original = dict(os.environ)

for k in os.environ.keys():
if k.startswith(("_CI_DD_", "DD_CIVISIBILITY_", "DD_SITE")):
del os.environ[k]

# Update based on the passed in arguments
os.environ.update(env)
try:
Expand Down

0 comments on commit 657bb84

Please sign in to comment.