Code Monkey home page Code Monkey logo

Comments (13)

olegpidsadnyi avatar olegpidsadnyi commented on May 31, 2024

@sliverc what's models.Attachment? is it just a dict?

from pytest-factoryboy.

sliverc avatar sliverc commented on May 31, 2024

No it is a simple django model.

class Attachment(models.Model):
    path = models.ImageField(max_length=1024)

I think the problem is caused through a factory boy change where ImageField resp. FileField is now derived from a declarations.Dict class.

See https://github.com/FactoryBoy/factory_boy/blob/master/factory/django.py#L175

from pytest-factoryboy.

olegpidsadnyi avatar olegpidsadnyi commented on May 31, 2024

@sliverc I see.. wow.. in factoryboy 2.10.0 ImageField is a SubFactory now, more than that - subclass of a Dict, this what brings the "dict" as a name of it's model. Not sure what kind of sense does it make.

Initially my idea was that SubFactory points to a factory of a model, for which you need a fixture.

from pytest-factoryboy.

olegpidsadnyi avatar olegpidsadnyi commented on May 31, 2024

Basically this:

import factory
from pytest_factoryboy import register


class Foo(dict):
    pass


@register
class FooFactory(factory.Factory):

    class Meta:
        model = Foo

    bar = factory.declarations.Dict({})


def test_foo(foo):
    """this test will lead to `fixture 'dict' not found` error."""
    pass

from pytest-factoryboy.

olegpidsadnyi avatar olegpidsadnyi commented on May 31, 2024

@sliverc We could fix it by comparing a type of the declaration. This would have an implication that people can't subclass SubFactory or RelatedFactory to refer to other models anymore.

Let's add an issue in factory-boy and ask what do they think why ImageField has to be a SubFactory.

from pytest-factoryboy.

sliverc avatar sliverc commented on May 31, 2024

I also don't quite see why it needs to be a subclass of SubFactory. Let's see what upstream has to say I guess.

from pytest-factoryboy.

noirbizarre avatar noirbizarre commented on May 31, 2024

Hi !

Is there any news or workaround for this one ?

from pytest-factoryboy.

olegpidsadnyi avatar olegpidsadnyi commented on May 31, 2024

@noirbizarre have you tried? I see Rafael has closed the issue FactoryBoy/factory_boy#451

from pytest-factoryboy.

olegpidsadnyi avatar olegpidsadnyi commented on May 31, 2024

@sliverc is it still an issue? can be closed?

from pytest-factoryboy.

sliverc avatar sliverc commented on May 31, 2024

I have tested it with the factory boy master and it works as expected. Thanks.

The only problem is that the factory boy change is not released yet so factory boy git master needs to be added as dependency for this to work.

I am fine with that and this issue can be closed. Question is whether others will still stumble upon this issue till factory boy has an official release with this fix.

from pytest-factoryboy.

noirbizarre avatar noirbizarre commented on May 31, 2024

I tried but on latest public release. If this is working with the master, it's fine to me and I'll wait for the release

from pytest-factoryboy.

sliverc avatar sliverc commented on May 31, 2024

Factory Boy has been released and I have tested it with version 2.11.1. It works so closing this issue. @olegpidsadnyi Thanks for having worked on this.

from pytest-factoryboy.

MRigal avatar MRigal commented on May 31, 2024

@sliverc This is actually still problematic when using factory.Dict and factory.List, as they are also subfactories... :-/

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.