Skip to content

Commit

Permalink
Merge pull request gem#10288 from gem/conftest
Browse files Browse the repository at this point in the history
Override the `_dj_autoclear_mailbox` test fixture in `pytest_django` to clear the outbox only if it exists
  • Loading branch information
micheles authored Jan 24, 2025
2 parents 479e6c6 + d5376e1 commit abacba9
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright (C) 2025, GEM Foundation
#
# OpenQuake is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# OpenQuake is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with OpenQuake. If not, see <http://www.gnu.org/licenses/>.

import pytest
from django.core import mail


@pytest.fixture(scope="function", autouse=True)
def _dj_autoclear_mailbox():
"""
Override the `_dj_autoclear_mailbox` test fixture in `pytest_django`
to clear the outbox only if it exists.
"""
if hasattr(mail, 'outbox'):
del mail.outbox[:]

0 comments on commit abacba9

Please sign in to comment.