Skip to content

Commit

Permalink
Add cleanup to _fail_for_invalid_template_variable fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
xavfernandez committed Oct 26, 2023
1 parent 787ceef commit c9c29aa
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions pytest_django/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,14 +628,17 @@ def __mod__(self, var: str) -> str:
else:
return msg

if (
os.environ.get(INVALID_TEMPLATE_VARS_ENV, "false") == "true"
and django_settings_is_configured()
):
from django.conf import settings as dj_settings
with pytest.MonkeyPatch.context() as mp:
if (
os.environ.get(INVALID_TEMPLATE_VARS_ENV, "false") == "true"
and django_settings_is_configured()
):
from django.conf import settings as dj_settings

if dj_settings.TEMPLATES:
mp.setitem(dj_settings.TEMPLATES[0]["OPTIONS"], "string_if_invalid", InvalidVarException())
yield

if dj_settings.TEMPLATES:
dj_settings.TEMPLATES[0]["OPTIONS"]["string_if_invalid"] = InvalidVarException()


@pytest.fixture(autouse=True)
Expand Down

0 comments on commit c9c29aa

Please sign in to comment.