Comments (9)
can't you just use autouse fixture for that?
and then separate db related tests via package so then fixture will be used only for tests using it
from pytest-factoryboy.
@bubenkoff I was thinking of trying it but
- I'm worried about the order, is it guaranteed to run first?
- I'm not sure how viable the package separation is, we have a few beastly functions which access up to five databases.
from pytest-factoryboy.
to be sure about the order you do need to explicitly declare that - i agree, so avoiding it is better
but autouse fixtures always go before the explicitly used ones
from pytest-factoryboy.
@underyx What kind of the base class are you using for your factories?
I'm using SQLAlchemy, so it is lazily bound to the same session maker that my test setup is using.
In what way your factory is storing the model? Basically what ORM are you using?
from pytest-factoryboy.
@underyx this doesn't look like very big overhead
@pytest.yield_fixture(scope='session')
def db_url():
with testing.postgresql.Postgresql() as db:
yield db.url()
if db
is session also scoped, then making it autouse is efficient
from pytest-factoryboy.
@underyx What kind of the base class are you using for your factories?
@olegpidsadnyi: factory.alchemy.SQLAlchemyModelFactory
I'm using SQLAlchemy as well — the factories.Session
in the issue description's code is an SQLAlchemy scoped_session
.
from pytest-factoryboy.
@underyx doing models.metadata.create_all(engine)
on every test if very inefficient
i would invest time in making tests isolated still, but sharing the same database during the whole session.
The way we do it is normally via randomization, using https://pypi.python.org/pypi/Faker
there's a plugin as well for it's integration pytest-faker
from pytest-factoryboy.
@bubenkoff well, alright, we have everything configured now with autouse=True
and it works. But it's still not ideal that any test run will automatically create all databases even when I run tests that don't need any database at all. Any chance of this feature making it into pytest-factoryboy?
from pytest-factoryboy.
@underyx At this point I don't see it is coming. It would be yet another magical point of declaring a dependency besides a factory class, fixture registration (partial specialization), fixture propagation via conftest.py and finally the @pytest.mark.parametrize.
This would be just an invitation to start abusing it when there are decent ways to configure the test suite.
from pytest-factoryboy.
Related Issues (20)
- Allow to register factories in the class namespace.
- pytest-factoryboy seems to break factory.django.mute_signals HOT 4
- Fix tests/test_postgen_dependencies::test_postgen_related
- AttributeError using `LazyFixture` in `register()` HOT 5
- Parent factory model name disregards `_name` override. HOT 1
- Ship tests with source distribution HOT 1
- function uses no argument HOT 1
- UserWarning: UserWarning: Using a <class 'list'> as model type for <ListFactory for <class 'list'>> is discouraged HOT 5
- Error `fixture not found` if define `register(_name=)` for connected SubFactory which is connected with another SubFactory HOT 1
- DeprecationWarning with pytest 7.2.0 HOT 4
- PytestAssertRewriteWarning
- Feature request: override name of factory fixture? HOT 3
- Alternative for `register`
- register with type hints HOT 3
- Improve handling of `factory.Maybe`
- Request other fixtures in fixtures generated by register HOT 3
- How can I pass function-scope fixtures (e.g. db sessions) to each Factory in combination with pytest-asyncio?
- Question regarding of usage of LazyFixture in @pytest.mark.parametrize on alias instead of chained fixture. HOT 1
- Broken support for Python 3.7 HOT 1
- 2.7.0: missing git version tag
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 pytest-factoryboy.