I've notice an issue with mongomock and pytest:
mongoengine.errors.NotUniqueError is not raised in my pytest environment, while it works in production with no mongomock db!
class User(LoginDocument):
id = db.SequenceField(primary_key=True)
email = db.EmailField(required=True, unique=True)
password_hash = db.StringField(required=True)
And this test fails:
def test_multiple_email(app, db):
with pytest.raises(NotUniqueError):
user1 = User(email="[email protected]", password="")
user1.save()
user2 = User(email="[email protected]", password="asd")
user2.save()
app = <Flask 'server'>
db = <flask_mongoengine.MongoEngine object at 0x10d45a9b0>
def test_multiple_email(app, db):
with pytest.raises(NotUniqueError):
user1 = User(email="[email protected]", password="")
user1.save()
user2 = User(email="[email protected]", password="asd")
> user2.save()
E Failed: DID NOT RAISE <class 'mongoengine.errors.NotUniqueError'>
Certainly this is a mongomock issue and not a mongoengine one.
Looks like this can be closed
Most helpful comment
Looks like this can be closed