I wrote the following test for my Django application. The IntegrationDaily model has a constraint of max. 100 capacity. Therefore the entry will fail "on purpose". However, pytest.raises(Exception)
seems to be the wrong approach to validate that. I also tried to import TransactionManagementError
instead but that didn't solve it either.
import pytest
from tests.factories.spaces import IntegrationDailyFactory
from myapp.spaces.models import IntegrationDaily
def describe_element_capacity_validation():
def with_is_failling():
with pytest.raises(Exception) as exc:
daily_element = IntegrationDailyFactory(capacity=300)
assert IntegrationDaily.objects.count() == 0