python - InvalidRequestError: Instance '<User at 0x7f65938a7510>' is not persisted -


I want to do such a test in the framework flask and receive the message:

 < Code> InvalidRequestError: Example '& lt; User 0x7f65938a7510 on & gt; '  

My test code:

  does not consist of file "classes.py" in class tests, line 31, test_removeProfil db.session.delete (user) (Unittest.TestCase): def test_removeProfil (self): user = user (name = "john", age = 33, email = "john@john.com") db.session.delete (user) db.session.commit () Self.assertNotEqual (user.name, "John") self.assertNotEqual (user.age, 33) self.assertNotEqual (user.email, "john@john.com")  

You are trying to delete a new instance, for example, you can get the database from either db.s To use ession.add () , or you want to use user = User.query.filter_by (email='john@john.com '). First () (or something like that) and delete it.

You may also have trouble reaching the properties of the destroyed installation (you consider deleting it from the top right) when you do a session, Limit ends. A database lookup is triggered in trying to use an expired attribute, but there can be no lookup for this object because it was deleted.

You can stop, but that is not normal behavior and you may have other problems.

You can also try calling on it.

Finally, you should actually leave the examples that have been removed. It is possible that whatever you are trying to do is a better way of doing it.


Comments