Skip to content

Commit

Permalink
Use custom options class to silence TypeErrors from FactoryOptions._f…
Browse files Browse the repository at this point in the history
…ill_from_meta
  • Loading branch information
ababic committed Oct 5, 2022
1 parent ac3884d commit 4d6f846
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/wagtail_factories/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import factory
from django.utils.text import slugify
from factory import errors, utils
from factory.base import FactoryOptions, OptionDefault
from factory.declarations import ParameteredAttribute
from wagtail.images import get_image_model

Expand Down Expand Up @@ -128,14 +129,23 @@ class PageFactoryMetaClass(FactoryMetaClass):
def __new__(mcs, class_name, bases, attrs):
new_class = super().__new__(mcs, class_name, bases, attrs)
PAGE_FACTORIES.append(new_class)
new_class._meta.autotest = getattr(new_class._meta, "autotest", True)
return new_class


class PageFactoryOptions(FactoryOptions):
def _build_default_options(self):
return super()._build_default_options() + [
OptionDefault("autotest", True, inherit=False),
]


class PageFactory(MP_NodeFactory, metaclass=PageFactoryMetaClass):

title = "Test page"
slug = factory.LazyAttribute(lambda obj: slugify(obj.title))

_options_class = PageFactoryOptions

class Meta:
model = Page
autotest = False
Expand Down

0 comments on commit 4d6f846

Please sign in to comment.