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
4 changes: 3 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ def tracer(use_global_tracer):
if use_global_tracer:
return ddtrace.tracer
else:
return DummyTracer()
t = DummyTracer()
yield t
t.shutdown()


@pytest.fixture
Expand Down
37 changes: 9 additions & 28 deletions tests/tracer/test_gitmetadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import pytest

from tests.subprocesstest import run_in_subprocess
from tests.utils import DummyTracer
from tests.utils import TracerTestCase


Expand Down Expand Up @@ -42,9 +41,7 @@ class GitMetadataTestCase(TracerTestCase):
DD_MAIN_PACKAGE="mypackage",
)
)
def test_gitmetadata_from_package(self):
tracer = DummyTracer()

def test_gitmetadata_from_package(self, tracer):
with tracer.trace("span") as s:
pass

Expand All @@ -57,9 +54,7 @@ def test_gitmetadata_from_package(self):
DD_TAGS="git.commit.sha:12345,git.repository_url:github.com/user/tag_repo",
)
)
def test_gitmetadata_from_DD_TAGS(self):
tracer = DummyTracer()

def test_gitmetadata_from_DD_TAGS(self, tracer):
with tracer.trace("span") as s:
pass

Expand All @@ -78,9 +73,7 @@ def test_gitmetadata_from_DD_TAGS(self):
DD_MAIN_PACKAGE="mypackage",
)
)
def test_gitmetadata_from_ENV(self):
tracer = DummyTracer()

def test_gitmetadata_from_ENV(self, tracer):
with tracer.trace("span") as s:
pass

Expand All @@ -102,9 +95,7 @@ def test_gitmetadata_from_ENV(self):
DD_TRACE_GIT_METADATA_ENABLED="false",
)
)
def test_gitmetadata_disabled(self):
tracer = DummyTracer()

def test_gitmetadata_disabled(self, tracer):
with tracer.trace("span") as s:
pass

Expand All @@ -121,9 +112,7 @@ def test_gitmetadata_disabled(self):
DD_MAIN_PACKAGE="pytest",
)
)
def test_gitmetadata_package_without_metadata(self):
tracer = DummyTracer()

def test_gitmetadata_package_without_metadata(self, tracer):
with tracer.trace("span") as s:
pass

Expand All @@ -141,9 +130,7 @@ def test_gitmetadata_package_without_metadata(self):
DD_MAIN_PACKAGE="mypackage",
)
)
def test_gitmetadata_from_env_filtering_https(self):
tracer = DummyTracer()

def test_gitmetadata_from_env_filtering_https(self, tracer):
with tracer.trace("span") as s:
pass

Expand All @@ -161,9 +148,7 @@ def test_gitmetadata_from_env_filtering_https(self):
DD_TAGS="git.commit.sha:12345,git.repository_url:https://username:[email protected]/user/tag_repo.git",
)
)
def test_gitmetadata_from_ddtags_filtering_https(self):
tracer = DummyTracer()

def test_gitmetadata_from_ddtags_filtering_https(self, tracer):
with tracer.trace("span") as s:
pass

Expand All @@ -182,9 +167,7 @@ def test_gitmetadata_from_ddtags_filtering_https(self):
DD_MAIN_PACKAGE="mypackage",
)
)
def test_gitmetadata_from_env_filtering_ssh(self):
tracer = DummyTracer()

def test_gitmetadata_from_env_filtering_ssh(self, tracer):
with tracer.trace("span") as s:
pass

Expand All @@ -202,9 +185,7 @@ def test_gitmetadata_from_env_filtering_ssh(self):
DD_TAGS="git.commit.sha:12345,git.repository_url:ssh://[email protected]/user/tag_repo.git",
)
)
def test_gitmetadata_from_ddtags_filtering_ssh(self):
tracer = DummyTracer()

def test_gitmetadata_from_ddtags_filtering_ssh(self, tracer):
with tracer.trace("span") as s:
pass

Expand Down
26 changes: 12 additions & 14 deletions tests/tracer/test_global_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from ddtrace.internal.settings._config import Config
from ddtrace.internal.settings.integration import IntegrationConfig

from ..utils import DummyTracer
from ..utils import override_env


Expand All @@ -17,7 +16,6 @@ class GlobalConfigTestCase(TestCase):
def setUp(self):
self.config = Config()
self.config.web = IntegrationConfig(self.config, "web")
self.tracer = DummyTracer()

def test_registration(self):
# ensure an integration can register a new list of settings
Expand Down Expand Up @@ -112,7 +110,7 @@ def test_settings_merge_deep(self):
assert self.config.requests["a"]["b"]["c"] is True
assert self.config.requests["a"]["b"]["d"] is True

def test_settings_hook(self):
def test_settings_hook(self, tracer):
"""
When calling `Hooks.emit()`
When there is a hook registered
Expand All @@ -125,7 +123,7 @@ def on_web_request(span):
span.set_tag("web.request", "/")

# Create our span
with self.tracer.start_span("web.request") as span:
with tracer.start_span("web.request") as span:
assert "web.request" not in span.get_tags()

# Emit the span
Expand All @@ -134,7 +132,7 @@ def on_web_request(span):
# Assert we updated the span as expected
assert span.get_tag("web.request") == "/"

def test_settings_hook_args(self):
def test_settings_hook_args(self, tracer):
"""
When calling `Hooks.emit()` with arguments
When there is a hook registered
Expand All @@ -148,7 +146,7 @@ def on_web_request(span, request, response):
span.set_tag("web.response", response)

# Create our span
with self.tracer.start_span("web.request") as span:
with tracer.start_span("web.request") as span:
assert "web.request" not in span.get_tags()

# Emit the span
Expand All @@ -159,7 +157,7 @@ def on_web_request(span, request, response):
assert span.get_tag("web.request") == "request"
assert span.get_tag("web.response") == "response"

def test_settings_hook_args_failure(self):
def test_settings_hook_args_failure(self, tracer):
"""
When calling `Hooks.emit()` with arguments
When there is a hook registered that is missing parameters
Expand All @@ -173,7 +171,7 @@ def on_web_request(span, request):
span.set_tag("web.request", request)

# Create our span
with self.tracer.start_span("web.request") as span:
with tracer.start_span("web.request") as span:
assert "web.request" not in span.get_tags()

# Emit the span
Expand All @@ -183,7 +181,7 @@ def on_web_request(span, request):
# Assert we did not update the span
assert "web.request" not in span.get_tags()

def test_settings_multiple_hooks(self):
def test_settings_multiple_hooks(self, tracer):
"""
When calling `Hooks.emit()`
When there are multiple hooks registered
Expand All @@ -204,7 +202,7 @@ def on_web_request3(span):
span.set_tag("web.method", "GET")

# Create our span
with self.tracer.start_span("web.request") as span:
with tracer.start_span("web.request") as span:
assert "web.request" not in span.get_tags()
assert "web.status" not in span.get_metrics()
assert "web.method" not in span.get_tags()
Expand All @@ -217,7 +215,7 @@ def on_web_request3(span):
assert span.get_metric("web.status") == 200
assert span.get_tag("web.method") == "GET"

def test_settings_hook_failure(self):
def test_settings_hook_failure(self, tracer):
"""
When calling `Hooks.emit()`
When the hook raises an exception
Expand All @@ -228,20 +226,20 @@ def test_settings_hook_failure(self):
self.config.web.hooks.register("request")(on_web_request)

# Create our span
with self.tracer.start_span("web.request") as span:
with tracer.start_span("web.request") as span:
# Emit the span
# DEV: This is the test, to ensure no exceptions are raised
self.config.web.hooks.emit("request", span)
on_web_request.assert_called()

def test_settings_no_hook(self):
def test_settings_no_hook(self, tracer):
"""
When calling `Hooks.emit()`
When no hook is registered
we do not raise an exception
"""
# Create our span
with self.tracer.start_span("web.request") as span:
with tracer.start_span("web.request") as span:
# Emit the span
# DEV: This is the test, to ensure no exceptions are raised
self.config.web.hooks.emit("request", span)
Expand Down
Loading