diff --git a/tests/test_models.py b/tests/test_models.py index 0f92d56..e1d5aa0 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -1,9 +1,6 @@ from __future__ import absolute_import, unicode_literals -try: - from test.support import EnvironmentVarGuard # Python < 3.10 -except ImportError: - from test.support.os_helper import EnvironmentVarGuard # Python >= 3.10 +from unittest import mock from django.test import TestCase from home.forms import CustomCaptchaFormBuilder @@ -21,11 +18,18 @@ class CaptchaTestingModeMixin(TestCase): """Allow Captcha to pass regardless of the value provided""" def setUp(self): - self.captcha_testing_mode_env = EnvironmentVarGuard() - self.captcha_testing_mode_env.set("RECAPTCHA_TESTING", "True") + # Use unittest.mock.patch to set the environment variable + self.captcha_testing_mode_patch = mock.patch.dict( + "os.environ", {"RECAPTCHA_TESTING": "True"} + ) + self.captcha_testing_mode_patch.start() self.captcha_form_data = {"recaptcha_response_field": "PASSED"} + def tearDown(self): + # Clean up the patch after the test + self.captcha_testing_mode_patch.stop() + class TestCaptchaEmailFormPageTestCase(CaptchaTestingModeMixin, TestCase): fixtures = ["test_data.json"] diff --git a/tests/testapp/testapp/settings.py b/tests/testapp/testapp/settings.py index c8766ea..6f0dc01 100644 --- a/tests/testapp/testapp/settings.py +++ b/tests/testapp/testapp/settings.py @@ -25,7 +25,7 @@ INSTALLED_APPS = wagtail_apps + [ "home", - "captcha", + "django_recaptcha", "wagtailcaptcha", "modelcluster", "taggit",