-
Notifications
You must be signed in to change notification settings - Fork 30
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
py.test seems not to be really supported #29
Comments
Hi! Just wondering if there has been any advance on this, since I'm looking for this functionality. |
Any news @mbegoc ? |
For any future visitors this is my workaround. from server.models import db as sqlalchemy_db
@pytest.fixture()
def seeded_db(app):
from flask_fixtures import load_fixtures_from_file
with app.app_context():
sqlalchemy_db.drop_all()
sqlalchemy_db.create_all()
sqlalchemy_db.session.rollback()
... # prepares seed_files_names and seed_dir_paths
for filename in seed_files_names:
load_fixtures_from_file(sqlalchemy_db, filename, seed_dir_paths)
yield sqlalchemy_db
sqlalchemy_db.session.expunge_all()
sqlalchemy_db.drop_all() I didn't use the And here is how you use that pytest fixture in a test case: def test_seeded_db(seeded_db):
"""
Test that seeded database works
We have a User table and a user.json seeding fixture file. So there should be some users in table.
"""
assert User.query.count() > 0
# now remove all user
User.query.delete()
seeded_db.session.commit()
assert User.query.count() == 0
def test_seeded_db_rollback(seeded_db):
"""
Test that the previous test did not affect the seeded database
"""
assert User.query.count() > 0 Seems to work for me as of now. If you have question you could reply to this thread. |
I tryed to use flask-fixtures for testing my project with py.test. It turned out that the only way to make fixtures load is to make the test class inherite from unittest.TestCase. Doing so make py.test run tests as unittest tests and act as a test container rather than the actual underlying test lib (it's at least how I understand what's going on here), and thus all the py.test fixture feature is deactivated. It's a huge issue, since I obviously need several fixture from pytest and pytest-flask to test my app (namely the client fixture). The claim that flask-fixtures support py.test seems to rely only on the fact that py.test can run many test lib like unittest. I think the doc should at least be clearer and warn about that, and maybe it would be even better not to claim to support py.test but just indicate that flask-fixtures tests can be run through py.test.
Anyway, I started to look into a way to make flask-fixtures fully support py.test, and if the project maintainer thinks it can be a good addition to the lib, I will go forward on this feature.
The text was updated successfully, but these errors were encountered: