Skip to content

Commit cf7d0da

Browse files
committed
add assertion that every test leaves the context empty
1 parent 5576876 commit cf7d0da

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

tests/conftest.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import pytest
2323

2424
import ddtrace
25+
from ddtrace._trace.provider import _DD_CONTEXTVAR
2526
from ddtrace.internal.compat import httplib
2627
from ddtrace.internal.compat import parse
2728
from ddtrace.internal.remoteconfig.client import RemoteConfigClient
@@ -67,6 +68,16 @@ def test_spans(tracer):
6768
container.reset()
6869

6970

71+
@pytest.fixture(autouse=True)
72+
def ensure_no_context_leak():
73+
try:
74+
yield
75+
finally:
76+
ctx = _DD_CONTEXTVAR.get()
77+
_DD_CONTEXTVAR.set(None)
78+
assert ctx is None
79+
80+
7081
@pytest.fixture
7182
def run_python_code_in_subprocess(tmpdir):
7283
def _run(code, **kwargs):

0 commit comments

Comments
 (0)