Created
June 3, 2017 12:16
-
-
Save c-rhodes/8682b920ae5796049c5d6ef99ee5be03 to your computer and use it in GitHub Desktop.
Django extensions import factory boy factories
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import django | |
django.setup() | |
import factory.base | |
import inspect | |
import importlib | |
factory_pre_imports = [] | |
for app_name in LOCAL_APPS: | |
module_name = '{}.{}'.format(app_name, 'factories') | |
try: | |
module = importlib.import_module(module_name) | |
except ImportError: | |
pass | |
module_factories = [] | |
for name, obj in inspect.getmembers(module): | |
if inspect.isclass(obj) and issubclass(obj, factory.base.BaseFactory): | |
module_factories.append(name) | |
factory_pre_imports.append((module_name, module_factories)) | |
SHELL_PLUS_PRE_IMPORTS = [] + factory_pre_imports |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment