Comments (6)
@olegpidsadnyi, this would be useful for another simple (but important) reason. You cannot use a factory in a fixture with scope other than function
. If you do, you get an error like You tried to access the 'function' scoped fixture 'factory' with a 'class' scoped request object
.
I think it would be best to give people the option. If they are messing with scopes, ideally they understand what they are doing and the potential foot-guns that come with that.
Not a big deal as we can always use the factory directly in these cases, but would be nice to have this.
from pytest-factoryboy.
Hey @olegpidsadnyi
I also want to suggest this change, in my case I have thousand of tests, nearly all of them need to create base DB structure consisting of approx. 60 db objects and because of the function scope each test creates these objects over and over only to delete them after the each of the tests completes.
Other case includes that each test case class have some objects which are common to each of it's test methods, so again we're creating same db objects and again we're deleting them between the tests.
from pytest-factoryboy.
currently not supported. I was never using model fixtures with the session scope because the entities of the data model are changed frequently.
For example author is not just one per your testing suite, right?
It is better for the test isolation to create new parents for every test.
Can you give me an example when author can be one for the whole session?
from pytest-factoryboy.
@NeveHanter We are not deleting the objects from our database and it is huge. This also improves your tests in terms of isolation, so that you don't get false positives or irrelevant items don't appear in collections.
I'm not also sure if you can register some fixtures as session scoped. Can session scoped fixture depend on non-session scoped? In case of relationships you can easily configure such inconsistent dependencies.
from pytest-factoryboy.
I'm quite surprised it is still not supported. I'm migrating Django project from unittest to pytest framework and this is big disadvantage. With big projects when you have factories that have subfactories that have subfactories, tests are slowing down drastically...
from pytest-factoryboy.
I think we can have this feature, but unfortunately, neither @olegpidsadnyi nor I have much spare time to address this.
Feel free to open a PR.
from pytest-factoryboy.
Related Issues (20)
- 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
- factory.SubFactory fixture collision when the model has the same name HOT 6
- `Trait`s not being considered by pytest_factoryboy
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.