Skip to content

Commit 38ba8de

Browse files
authored
Merge pull request #869 from jd/pytest4
Add support for pytest4
2 parents deecab3 + c8137aa commit 38ba8de

File tree

2 files changed

+19
-27
lines changed

2 files changed

+19
-27
lines changed

tests/opentracer/test_tracer_asyncio.py

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,34 @@
88
from ddtrace.opentracer.utils import get_context_provider_for_scope_manager
99

1010
from tests.contrib.asyncio.utils import AsyncioTestCase, mark_asyncio
11-
from .conftest import dd_tracer, ot_tracer_factory, writer
11+
from .conftest import ot_tracer_factory
1212

1313

1414
@pytest.fixture()
15-
def ot_tracer(ot_tracer_factory):
16-
return ot_tracer_factory(
15+
def ot_tracer(request, ot_tracer_factory):
16+
# use the dummy asyncio ot tracer
17+
request.instance.ot_tracer = ot_tracer_factory(
1718
"asyncio_svc",
1819
config={},
1920
scope_manager=AsyncioScopeManager(),
2021
context_provider=ddtrace.contrib.asyncio.context_provider,
2122
)
23+
request.instance.ot_writer = request.instance.ot_tracer._dd_tracer.writer
24+
request.instance.dd_tracer = request.instance.ot_tracer._dd_tracer
2225

23-
26+
@pytest.mark.usefixtures("ot_tracer")
2427
class TestTracerAsyncio(AsyncioTestCase):
25-
def setUp(self):
26-
super(TestTracerAsyncio, self).setUp()
27-
28-
# use the dummy asyncio ot tracer
29-
self.tracer = ot_tracer(ot_tracer_factory())
30-
self.writer = writer(self.tracer)
3128

3229
def reset(self):
33-
self.writer.pop_traces()
30+
self.ot_writer.pop_traces()
3431

3532
@mark_asyncio
3633
def test_trace_coroutine(self):
3734
# it should use the task context when invoked in a coroutine
38-
with self.tracer.start_span("coroutine"):
35+
with self.ot_tracer.start_span("coroutine"):
3936
pass
4037

41-
traces = self.writer.pop_traces()
38+
traces = self.ot_writer.pop_traces()
4239

4340
assert len(traces) == 1
4441
assert len(traces[0]) == 1
@@ -51,16 +48,16 @@ def test_trace_multiple_coroutines(self):
5148
@asyncio.coroutine
5249
def coro():
5350
# another traced coroutine
54-
with self.tracer.start_active_span("coroutine_2"):
51+
with self.ot_tracer.start_active_span("coroutine_2"):
5552
return 42
5653

57-
with self.tracer.start_active_span("coroutine_1"):
54+
with self.ot_tracer.start_active_span("coroutine_1"):
5855
value = yield from coro()
5956

6057
# the coroutine has been called correctly
6158
assert value == 42
6259
# a single trace has been properly reported
63-
traces = self.writer.pop_traces()
60+
traces = self.ot_writer.pop_traces()
6461
assert len(traces) == 1
6562
assert len(traces[0]) == 2
6663
assert traces[0][0].name == "coroutine_1"
@@ -73,13 +70,13 @@ def coro():
7370
def test_exception(self):
7471
@asyncio.coroutine
7572
def f1():
76-
with self.tracer.start_span("f1"):
73+
with self.ot_tracer.start_span("f1"):
7774
raise Exception("f1 error")
7875

7976
with pytest.raises(Exception):
8077
yield from f1()
8178

82-
traces = self.writer.pop_traces()
79+
traces = self.ot_writer.pop_traces()
8380
assert len(traces) == 1
8481
spans = traces[0]
8582
assert len(spans) == 1
@@ -95,29 +92,24 @@ def test_trace_multiple_calls(self):
9592
@asyncio.coroutine
9693
def coro():
9794
# another traced coroutine
98-
with self.tracer.start_span("coroutine"):
95+
with self.ot_tracer.start_span("coroutine"):
9996
yield from asyncio.sleep(0.01)
10097

10198
futures = [asyncio.ensure_future(coro()) for x in range(10)]
10299
for future in futures:
103100
yield from future
104101

105-
traces = self.writer.pop_traces()
102+
traces = self.ot_writer.pop_traces()
106103

107104
assert len(traces) == 10
108105
assert len(traces[0]) == 1
109106
assert traces[0][0].name == "coroutine"
110107

111108

109+
@pytest.mark.usefixtures("ot_tracer")
112110
class TestTracerAsyncioCompatibility(AsyncioTestCase):
113111
"""Ensure the opentracer works in tandem with the ddtracer and asyncio."""
114112

115-
def setUp(self):
116-
super(TestTracerAsyncioCompatibility, self).setUp()
117-
self.ot_tracer = ot_tracer(ot_tracer_factory())
118-
self.dd_tracer = dd_tracer(self.ot_tracer)
119-
self.writer = writer(self.ot_tracer)
120-
121113
@mark_asyncio
122114
def test_trace_multiple_coroutines_ot_dd(self):
123115
"""

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ deps =
127127
# distribution build.
128128
!ddtracerun: wrapt
129129
!msgpack03-!msgpack04-!msgpack05-!ddtracerun: msgpack-python
130-
pytest>=3.0.0,<4.0.0
130+
pytest>=3
131131
opentracing
132132
# test dependencies installed in all envs
133133
mock

0 commit comments

Comments
 (0)