MCPcopy Create free account
hub / github.com/AgentOps-AI/agentops / test_start_trace_without_init

Function test_start_trace_without_init

tests/unit/test_session.py:133–165  ·  view source on GitHub ↗

Test starting a trace without initialization triggers auto-init

()

Source from the content-addressed store, hash-verified

131
132
133def test_start_trace_without_init():
134 """Test starting a trace without initialization triggers auto-init"""
135 import agentops
136
137 # Reset client for test
138 agentops._client = agentops.Client()
139
140 # Mock global tracer to be uninitialized initially, then initialized after init
141 with (
142 patch("agentops.tracer") as mock_tracer,
143 patch("agentops.client.client.tracer", mock_tracer),
144 patch("agentops.sdk.decorators.factory.tracer", mock_tracer),
145 patch("agentops.legacy.tracer", mock_tracer),
146 ):
147 mock_tracer.initialized = False
148
149 # Mock the init function to simulate successful initialization
150 with patch("agentops.init") as mock_init:
151
152 def side_effect():
153 # After init is called, mark global tracer as initialized
154 mock_tracer.initialized = True
155
156 mock_init.side_effect = side_effect
157 mock_tracer.start_trace.return_value = None
158
159 # Try to start a trace without initialization
160 result = agentops.start_trace(trace_name="test_trace")
161
162 # Verify that init was called automatically
163 mock_init.assert_called_once()
164 # Should return None since start_trace returned None
165 assert result is None
166
167
168def test_end_trace(mock_tracing_core, mock_trace_context):

Callers

nothing calls this directly

Calls 1

start_traceMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…