Code Monkey home page Code Monkey logo

Comments (8)

nicoCalvo avatar nicoCalvo commented on May 31, 2024 6

+1

from pytest-factoryboy.

revmischa avatar revmischa commented on May 31, 2024 2

2+ years later, no comments. Fantastic!

Open a PR or request a refund

from pytest-factoryboy.

joriskoris-emburse avatar joriskoris-emburse commented on May 31, 2024 1

2+ years later, no comments. Fantastic!

from pytest-factoryboy.

ttphan avatar ttphan commented on May 31, 2024

Confirmed, same error when using it in combination with SQLAlchemy.

from pytest-factoryboy.

revmischa avatar revmischa commented on May 31, 2024

Got this too

from pytest-factoryboy.

lovetoburnswhen avatar lovetoburnswhen commented on May 31, 2024

Anyone have any luck? I'm getting this with custom objects still on latest version

from pytest-factoryboy.

youtux avatar youtux commented on May 31, 2024

nowadays pytest-factoryboy gives this warning:

 Using a <class 'list'> as model type for <ListFactory for <class 'list'>> is discouraged by pytest-factoryboy, as it assumes that the model name is 'list' when using it as SubFactory or RelatedFactory, which is too generic and probably not what you want.
   You can giving an explicit name to the model by using:
   model = named_model(list, "Foo")
        factory_class = <class 'factory.base.ListFactory'>
        model_cls  = <class 'list'>
        model_name = 'list'

Try that out, it should probably fix your issue.

from pytest-factoryboy.

youtux avatar youtux commented on May 31, 2024

anyway, this is the most correct way I can think of to fix the initial issue posted by @sanchez-escobar:

import factory
from pytest_factoryboy import register


class ClassA:
    def __init__(self, val):
        self.val = val


class ClassB:
    def __init__(self, arr):
        self.arr = arr


class ClassAFactory(factory.Factory):
    """TestClassA factory."""

    class Meta:
        model = ClassA

    val = "test_value"


class ClassBFactory(factory.Factory):
    """TestClassB factory."""

    class Meta:
        model = ClassB

    class Params:
        arr_0 = factory.SubFactory(ClassAFactory)

    arr = factory.LazyAttribute(lambda o: [o.arr_0])


register(ClassAFactory)
register(ClassBFactory)


def test_example_a(class_a):
    """
    Assert that the nested list is properly tested
    """
    assert class_a.val == "test_value"


def test_example_b(class_b):
    """
    Assert that the nested list is properly tested
    """
    assert len(class_b.arr) == 1

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.