I'm getting an error of Module not found when trying to create a test function to mock the get method of sqlalchemy query (with pytest)
example:
from mock import patch
@patch('flask_sqlalchemy._QueryProperty.__get__')
def test_get_all(queryMock):
assert True
When running pytest i get an error:
ModuleNotFoundError: No module named 'flask_sqlalchemy._QueryProperty'
I'm using the 3.0.2 version of Flask-SQLAlchemy. So i just changed to version 2.5.1 and it worked. However i think would be good to use the latest version. Is there any other way to mock the sql-alchemy query that works with the latest versions?
Use flask_sqlalchemy.model._QueryProperty.__get__ instead of flask_sqlalchemy._QueryProperty.__get__. This will resolve your issue as _QueryProperty class has been moved into model.
from mock import patch
@patch('flask_sqlalchemy.model._QueryProperty.__get__')
def test_get_all(queryMock):
assert True
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With