88from ddtrace .opentracer .utils import get_context_provider_for_scope_manager
99
1010from 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" )
2427class 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" )
112110class 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 """
0 commit comments