Skip to content

Commit a9c824e

Browse files
committed
fix tests for 3.9
1 parent 40204f7 commit a9c824e

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

ddtrace/internal/core/events.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def additional_handler(event_instance):
2626
2727
This example shows how ``core.context_with_data()`` can be replaced by `core.context_with_event()`::
2828
29-
@span_context
29+
@context_event
3030
class TestContextEvent(SpanContextEvent):
3131
# SpanContextEvent requires this attributes
3232
event_name = "test.event"
@@ -115,11 +115,14 @@ def context_event(cls: Any) -> Any:
115115
class MyEvent(SpanContextEvent):
116116
url: str # Automatically gets event_field() applied
117117
"""
118-
annotations = getattr(cls, "__annotations__", {})
118+
119+
annotations = cls.__dict__.get("__annotations__", {})
119120

120121
# For each annotated field without a default, set it to event_field()
121122
for name, _ in annotations.items():
122-
if not hasattr(cls, name):
123+
# Only apply `event_field()` for fields that don't define a default value
124+
# in the class body.
125+
if name not in cls.__dict__:
123126
setattr(cls, name, event_field())
124127

125128
return dataclass(cls)

tests/internal/events/test_context_event.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
from types import TracebackType
23
from typing import Optional
34
from typing import Tuple
@@ -78,8 +79,12 @@ def _on_context_ended(
7879
assert len(_listeners[f"context.ended.{TestContextEvent.event_name}"].values()) == 1
7980

8081

82+
@pytest.mark.skipif(sys.version_info < (3, 10), reason="Requires Python 3.10+")
8183
def test_context_event_enforce_kwargs_error():
82-
"""Test that missing required fields raise TypeError."""
84+
"""Test that missing required fields raise TypeError.
85+
On Python 3.9, we create a default value to every attributes because kw_only
86+
is not available in dataclass field. Therefore we skip the test
87+
"""
8388
called = []
8489

8590
@context_event

0 commit comments

Comments
 (0)