@@ -825,3 +825,62 @@ def mocked_make_msgid(*args, **kwargs):
825
825
result = django_pytester .runpytest_subprocess ("--tb=short" , "-vv" , "-s" )
826
826
result .stdout .fnmatch_lines (["*test_mailbox_inner*" , "django_mail_dnsname_mark" , "PASSED*" ])
827
827
assert result .ret == 0
828
+
829
+
830
+ @pytest .mark .django_project (
831
+ create_manage_py = True ,
832
+ extra_settings = """
833
+ EMAIL_BACKEND = "django.core.mail.backends.dummy.EmailBackend"
834
+ """ ,
835
+ )
836
+ def test_mail_auto_fixture_misconfigured (django_pytester : DjangoPytester ) -> None :
837
+ """
838
+ django_test_environment fixture can be overridden by user, and that would break mailoutbox fixture.
839
+
840
+ Normally settings.EMAIL_BACKEND is set to "django.core.mail.backends.locmem.EmailBackend" by django,
841
+ along with mail.outbox = []. If this function doesn't run for whatever reason, the
842
+ mailoutbox fixture will not work properly.
843
+ """
844
+ django_pytester .create_test_module (
845
+ """
846
+ import pytest
847
+
848
+ @pytest.fixture(autouse=True, scope="session")
849
+ def django_test_environment(request):
850
+ yield
851
+ """ ,
852
+ filename = "conftest.py" ,
853
+ )
854
+
855
+ django_pytester .create_test_module (
856
+ """
857
+ def test_with_fixture(settings, mailoutbox):
858
+ assert mailoutbox == []
859
+ assert settings.EMAIL_BACKEND == "django.core.mail.backends.dummy.EmailBackend"
860
+
861
+ def test_without_fixture():
862
+ from django.core import mail
863
+ assert not hasattr(mail, "outbox")
864
+ """
865
+ )
866
+ result = django_pytester .runpytest_subprocess ()
867
+ result .assert_outcomes (passed = 2 )
868
+
869
+
870
+ @pytest .mark .django_project (create_settings = False )
871
+ def test_no_settings (django_pytester : DjangoPytester ) -> None :
872
+ django_pytester .create_test_module (
873
+ """
874
+ def test_skipped_settings(settings):
875
+ assert False
876
+
877
+ def test_skipped_mailoutbox(mailoutbox):
878
+ assert False
879
+
880
+ def test_mail():
881
+ from django.core import mail
882
+ assert not hasattr(mail, "outbox")
883
+ """
884
+ )
885
+ result = django_pytester .runpytest_subprocess ()
886
+ result .assert_outcomes (passed = 1 , skipped = 2 )
0 commit comments