-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Items created in db_session
not accessible with client_class
#19
Comments
Weirdly, when I do: import pytest
from mymodels import MyItem
from flask import url_for
@pytest.mark.usefixtures('client_class')
class TestMyApp:
def test_add(self, db_session, uid):
res = self.client.post(url_for('myapi.ItemResource', name='x'))
assert res.status_code == 200
item_id = res.json['result']['id']
item = db_session.query(MyItem).filter_by(id=item_id).one()
db_session.delete(item)
db_session.flush()
with pytest.raises(NoResultFound):
db_session.query(MyItem).filter_by(id=item_id).one() it seems to work. indicating that things I create with |
Hm, that's pretty weird. From a quick scan, I can't see anything in your config that looks obviously wrong. Out of curiousity, would it be relatively simple to run the tests against Postgres instead of Sqlite? I haven't tested the plugin against Sqlite before and I'm wondering if there's something about the implementation of nested transactions that's interfering with your tests (some evidence that may be true here). If a quick port to Postgres is too strenuous, I'll try a simple replication of your case in Sqlite and see if I can reproduce the error. |
Another question: Do you see similar errors when you run updates against records, or only when you create them with the model ORM (as it looks like is happening in |
I have a similar issue to this, and I tracked it down to the session used in my app is different to the session that's used in my tests. I setup SQLAlchemy in my app like so: src/takumi/extensions.py:
src/takumi/app.py:
then src/takumi/application.py:
We access the session and create models in our code like so:
It occurred to me that perhaps it's something to do with instantiating the We're using PostgreSQL. I also had the following in our setup.cfg:
|
I have a conftest:
And then have:
When i run the test, it always fails with a 404 error saying that the provided ID does not exist
The text was updated successfully, but these errors were encountered: