Comments (3)
Hi! Just wondering if there has been any advance on this, since I'm looking for this functionality.
from flask-fixtures.
Any news @mbegoc ?
from flask-fixtures.
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 flask_fixtures.setup
or flask_fixtures.teardown
becuase I want to manage context myself. I also disliked how it finds seeding fixture files. But those are not really important.
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.
from flask-fixtures.
Related Issues (20)
- SQLite gotcha HOT 2
- Add support for standalone test functions
- Missing FixturesMixin HOT 13
- update PyPi docs HOT 1
- Create a better plugin system for fixtures loaders
- Doing per-test fixtures? HOT 2
- Possible issue with bit fields
- Database initialization HOT 1
- Many-to-many issue HOT 1
- Application not registered on db instance and no application bound to current context HOT 7
- class level model didn't work
- Flask-Fixtures will parse string containing numbers as datetime HOT 7
- PyYAML deprecation warning
- Run fixtures in every test
- Add Flask-Fixtures in conda-forge channel HOT 1
- Keeping fixtures after unit tests
- setUp function not working when decorating individual methods HOT 1
- Add Python 3 compatibility HOT 1
- Add a simple variable replacement templating syntax for fixtures HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flask-fixtures.