Доброго дня, нужна помощь с вопросом тестирования блока except в джанге, который не поднимает исключение
@receiver(post_save, sender=AgentRequest)
def action_after_save(instance, **kwargs):
try:
send_email(instance)
except Exception as e:
logger = logging.getLogger("Send mail")
logger.error(f"Ошибка отправки {str(e)}")
#raise e # ЕСЛИ РАССКОМЕНТИРУЮ ТЕСТ ПРОЙДЁТ
class AgentTest(TestCase):
def test_action_after_save(self):
"""Тест action_after_save"""
with self.assertRaises(Exception):
action_after_save(instance=None)
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
Ошибка отправки 'NoneType' object has no attribute 'email_text'
F...
======================================================================
FAIL: test_action_after_save (agent.tests.AgentTest.test_action_after_save)
Тест action_after_save
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/app/web/agent/tests.py", line 57, in test_action_after_save
with self.assertRaises(Exception):
AssertionError: Exception not raised
----------------------------------------------------------------------