Comments (4)
As a work around I use this method:
register(OAuthPayloadFactory, _name='o_auth_payload')
but it feels weird.
from pytest-factoryboy.
New workaround:
import factory
from mimesis_factory import MimesisField
from pytest_factoryboy import register
try:
from mypy_extensions import TypedDict # typechecks your dicts
except ImportError:
TypedDict = dict # does nothing
class GitlabUserPayload(TypedDict):
"""
Gitlab API response for user endpoint request.
We define this class here, since we do not actually use it in the code.
"""
username: str
email: str
name: str
@register
class GitlabUserPayloadFactory(factory.BaseDictFactory):
"""Fake factory for Gitlab's user response."""
class Meta:
model = GitlabUserPayload
username = MimesisField('username')
email = MimesisField('email')
name = MimesisField('full_name')
from pytest-factoryboy.
Actually the behaviour you are describing is not the bug. The name of the fixture by the convention, as stated in the docs is:
- for factory fixture: its lowercase-underscore class name
- for model fixture: its underlying model's lowercase-underscore class name (docs are not phrased well in this case)
So in first case there is no underlying model called OAuthPayload
, therefore there is no model fixture called o_auth_payload
as you would expect. The underlying model for this factory (as it is derived from factory.DictFactory
) is dict
as stated in DictFactory
definition here. This means that the name of the model fixture would be dict
in this case. That is exactly why example with GitlabUserPayload
model works as you would expect it to.
from pytest-factoryboy.
Fixed in #167
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.