Code Monkey home page Code Monkey logo

Comments (4)

sobolevn avatar sobolevn commented on June 9, 2024

As a work around I use this method:

register(OAuthPayloadFactory, _name='o_auth_payload')

but it feels weird.

from pytest-factoryboy.

sobolevn avatar sobolevn commented on June 9, 2024

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.

phankiewicz avatar phankiewicz commented on June 9, 2024

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.

youtux avatar youtux commented on June 9, 2024

Fixed in #167

from pytest-factoryboy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.