FactoryBoy / factory_boy

A test fixtures replacement for Python
https://factoryboy.readthedocs.io/
MIT License
3.49k stars 392 forks source link

DictFactory does not override _setup_next_sequence #993

Open martsime opened 1 year ago

martsime commented 1 year ago

Description

Overriding _setup_next_sequence does not work when subclassing DictFactory, but I get it to work for other factories subclassing DjangoModelFactory.

Model / Factory code
import factory

class TestDictFactory(factory.DictFactory):
    @classmethod
    def _setup_next_sequence(cls) -> int:
        return 10

    number = factory.Sequence(lambda n: n)

Test case

A simple test case where the sequence should start from 10

def test_dict_factory():
    test = TestDictFactory()
    assert test["number"] == 10
Output
=========================================== test session starts ===========================================
platform darwin -- Python 3.10.6, pytest-7.2.0, pluggy-1.0.0
django: ...
rootdir: ...
plugins: Faker-15.1.3, mock-3.10.0, django-4.5.2
collected 61 items / 60 deselected / 1 selected

tests/test_factories.py F                                                                [100%]

================================================ FAILURES =================================================
____________________________________________ test_dict_factory ____________________________________________

    def test_dict_factory():
        test = TestDictFactory()
>       assert test["number"] == 10
E       assert 0 == 10

tests/test_factories.py:23: AssertionError
danjer commented 8 months ago

Hey I would like to work on this issue if thats okay :) I have made a proposal for a patch on in this PR: https://github.com/FactoryBoy/factory_boy/pull/1056. I'm curious to hear if this is in line with your vision :) cheers!