Pytest не вызывает ошибку ValidationError
Я пытаюсь проверить, что пользователь не может быть одновременно агентом и организатором, но pytest не выдает ValidationError.
models.py
class User(AbstractUser):
email = models.EmailField(unique=True)
is_organizer = models.BooleanField(default=False)
is_agent = models.BooleanField(default=False, )
def clean(self):
super().clean()
if self.is_organizer and self.is_agent:
raise ValidationError("User can't be Agent and Organizer at the same time")
test
@pytest.mark.django_db()
def test_user_cant_be_organizer_and_agent_at_the_same_time():
# user = User(username='ali', email='ali@gmail.com', password='a.123456', is_agent=False, is_organizer=True)
# user.full_clean()
with pytest.raises(ValidationError):
User(username='a', email='a@gmail.com', password='a.123456', is_agent=True, is_organizer=True)
pytest error
core\tests\test_users.py:21 (test_user_cant_be_organizer_and_agent_at_the_same_time)
@pytest.mark.django_db()
def test_user_cant_be_organizer_and_agent_at_the_same_time():
# user = User(username='ali', email='ali@gmail.com', password='a.123456', is_agent=False, is_organizer=True)
# user.full_clean()
with pytest.raises(ValidationError):
> User(username='a', email='a@gmail.com', password='a.123456', is_agent=True, is_organizer=True)
E Failed: DID NOT RAISE <class 'django.core.exceptions.ValidationError'>
test_users.py:28: Failed
Destroying test database for alias 'default' ('test_crm')...