Skip to content

Commit

Permalink
fix: add a fixture to set and reset Adapters (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
diefans authored Dec 5, 2024
1 parent b85dd6b commit 0ceec71
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/buvar/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ def pytest_pyfunc_call(pyfuncitem):

def wrap_in_buvar_plugin_context(context, func):
"""Enable test function to run in plugin context."""
import functools
import contextvars
import functools

from buvar.context import buvar_context

Expand All @@ -117,3 +117,15 @@ def wrapper():
return ctx.run(wrapper)

return inner


@pytest.fixture
def buvar_adapters_setup_contextvars():
"""Set and reset adapters.
This fixture should be used, if you need to reset adapter registration for a test.
"""
from buvar import di

token = di.buvar_adapters.set(di.Adapters())
yield
di.buvar_adapters.reset(token)

0 comments on commit 0ceec71

Please sign in to comment.