@@ -864,3 +864,62 @@ def mocked_make_msgid(*args, **kwargs):
864
864
result = django_pytester .runpytest_subprocess ("--tb=short" , "-vv" , "-s" )
865
865
result .stdout .fnmatch_lines (["*test_mailbox_inner*" , "django_mail_dnsname_mark" , "PASSED*" ])
866
866
assert result .ret == 0
867
+
868
+
869
+ @pytest .mark .django_project (
870
+ create_manage_py = True ,
871
+ extra_settings = """
872
+ EMAIL_BACKEND = "django.core.mail.backends.dummy.EmailBackend"
873
+ """ ,
874
+ )
875
+ def test_mail_auto_fixture_misconfigured (django_pytester : DjangoPytester ) -> None :
876
+ """
877
+ django_test_environment fixture can be overridden by user, and that would break mailoutbox fixture.
878
+
879
+ Normally settings.EMAIL_BACKEND is set to "django.core.mail.backends.locmem.EmailBackend" by django,
880
+ along with mail.outbox = []. If this function doesn't run for whatever reason, the
881
+ mailoutbox fixture will not work properly.
882
+ """
883
+ django_pytester .create_test_module (
884
+ """
885
+ import pytest
886
+
887
+ @pytest.fixture(autouse=True, scope="session")
888
+ def django_test_environment(request):
889
+ yield
890
+ """ ,
891
+ filename = "conftest.py" ,
892
+ )
893
+
894
+ django_pytester .create_test_module (
895
+ """
896
+ def test_with_fixture(settings, mailoutbox):
897
+ assert mailoutbox == []
898
+ assert settings.EMAIL_BACKEND == "django.core.mail.backends.dummy.EmailBackend"
899
+
900
+ def test_without_fixture():
901
+ from django.core import mail
902
+ assert not hasattr(mail, "outbox")
903
+ """
904
+ )
905
+ result = django_pytester .runpytest_subprocess ()
906
+ result .assert_outcomes (passed = 2 )
907
+
908
+
909
+ @pytest .mark .django_project (create_settings = False )
910
+ def test_no_settings (django_pytester : DjangoPytester ) -> None :
911
+ django_pytester .create_test_module (
912
+ """
913
+ def test_skipped_settings(settings):
914
+ assert False
915
+
916
+ def test_skipped_mailoutbox(mailoutbox):
917
+ assert False
918
+
919
+ def test_mail():
920
+ from django.core import mail
921
+ assert not hasattr(mail, "outbox")
922
+ """
923
+ )
924
+ result = django_pytester .runpytest_subprocess ()
925
+ result .assert_outcomes (passed = 1 , skipped = 2 )
0 commit comments