Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DictFactory does not override _setup_next_sequence #993

Open
martsime opened this issue Nov 17, 2022 · 1 comment · May be fixed by #1056
Open

DictFactory does not override _setup_next_sequence #993

martsime opened this issue Nov 17, 2022 · 1 comment · May be fixed by #1056
Labels

Comments

@martsime
Copy link

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 added a commit to danjer/factory_boy that referenced this issue Dec 29, 2023
danjer added a commit to danjer/factory_boy that referenced this issue Dec 29, 2023
@danjer
Copy link

danjer commented Dec 29, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants