Skip to content

Commit

Permalink
conftest: fix _template_string_if_invalid_marker fixture
Browse files Browse the repository at this point in the history
to reset fail to True after a mark has been used.

And add the missing marks on failing tests
  • Loading branch information
xavfernandez committed Oct 25, 2023
1 parent eb7ca24 commit ba56c1d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,22 @@ def _fail_for_invalid_template_variable_improved(_fail_for_invalid_template_vari
)


@pytest.fixture(autouse=True)
def _template_string_if_invalid_marker(monkeypatch, request) -> None:
# TODO: remove me once https://github.com/pytest-dev/pytest-django/pull/1076 is merged & released
marker = request.keywords.get("ignore_template_errors", None)
if os.environ.get(INVALID_TEMPLATE_VARS_ENV, "false") == "true":
if marker and django_settings_is_configured():
from django.conf import settings as dj_settings

if dj_settings.TEMPLATES:
monkeypatch.setattr(
dj_settings.TEMPLATES[0]["OPTIONS"]["string_if_invalid"],
"fail",
False,
)


@pytest.fixture(scope="session", autouse=True)
def make_unordered_queries_randomly_ordered():
"""
Expand Down
3 changes: 3 additions & 0 deletions tests/www/approvals_views/test_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
from tests.utils.test import parse_response_to_soup


pytestmark = pytest.mark.ignore_template_errors


class TestApprovalDetailView:
def test_anonymous_user(self, client):
approval = ApprovalFactory()
Expand Down
4 changes: 4 additions & 0 deletions tests/www/approvals_views/test_display.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from unittest.mock import PropertyMock, patch

import pytest
from dateutil.relativedelta import relativedelta
from django.urls import reverse
from freezegun import freeze_time
Expand All @@ -11,6 +12,9 @@
from tests.utils.test import TestCase


pytestmark = pytest.mark.ignore_template_errors


@patch.object(JobApplication, "can_be_cancelled", new_callable=PropertyMock, return_value=False)
class TestDisplayApproval(TestCase):
@freeze_time("2023-04-26")
Expand Down
4 changes: 4 additions & 0 deletions tests/www/invitations_views/test_prescriber_organization.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import timedelta
from urllib.parse import urlencode

import pytest
import respx
from allauth.account.models import EmailAddress
from django.conf import settings
Expand Down Expand Up @@ -36,6 +37,9 @@
INVITATION_URL = reverse("invitations_views:invite_prescriber_with_org")


pytestmark = pytest.mark.ignore_template_errors


class TestSendPrescriberWithOrgInvitation(TestCase):
def setUp(self):
super().setUp()
Expand Down
4 changes: 4 additions & 0 deletions tests/www/invitations_views/test_siae_accept.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from urllib.parse import urlencode

import pytest
import respx
from django.conf import settings
from django.contrib import messages
Expand All @@ -21,6 +22,9 @@
from tests.utils.test import assertMessages


pytestmark = pytest.mark.ignore_template_errors


class TestAcceptInvitation(InclusionConnectBaseTestCase):
def assert_accepted_invitation(self, response, invitation, user):
user.refresh_from_db()
Expand Down

0 comments on commit ba56c1d

Please sign in to comment.