When running the test suite for [whitenoise](https://github.com/evansd/whitenoise) plenty of tests ends with the following error (using pytest-6.2.5, pytest-django-4.5.2): ``` [ 31s] _______ ERROR at setup of test_last_modified_not_set_when_mtime_is_zero ________ [ 31s] [ 31s] @pytest.fixture(scope="function", autouse=True) [ 31s] def _dj_autoclear_mailbox() -> None: [ 31s] if not django_settings_is_configured(): [ 31s] return [ 31s] [ 31s] from django.core import mail [ 31s] [ 31s] > if mail.outbox: [ 31s] E AttributeError: module 'django.core.mail' has no attribute 'outbox' [ 31s] ``` When reading on the `mail.outbox` I found that it [doesn’t exist quite often](https://stackoverflow.com/q/5424498/164233), so this fixture has protection against it. When I apply this patch: ```diff --- pytest_django/plugin.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/pytest_django/plugin.py +++ b/pytest_django/plugin.py @@ -502,7 +502,8 @@ def _dj_autoclear_mailbox() -> None: from django.core import mail - del mail.outbox[:] + if hasattr(mail, "outbox"): + del mail.outbox[:] @pytest.fixture(scope="function") ``` Tests pass without a problem.