Errors with factory_boy master: 'FactoryOptions' object has no attribute 'postgen_declarations'
See original GitHub issueThere are errors with factory_boy
master:
================================================ ERRORS ================================================
_______________________________ ERROR collecting tests/test_circular.py ________________________________
tests/test_circular.py:50: in <module>
register(AuthorFactory)
.tox/py36-pytest3/lib/python3.6/site-packages/pytest_factoryboy/fixture.py:60: in register
deps = get_deps(factory_class, model_name=model_name)
.tox/py36-pytest3/lib/python3.6/site-packages/pytest_factoryboy/fixture.py:154: in get_deps
for attr, value in factory_class.declarations(factory_class._meta.postgen_declarations).items()
E AttributeError: 'FactoryOptions' object has no attribute 'postgen_declarations'
___________________________ ERROR collecting tests/test_factory_fixtures.py ____________________________
tests/test_factory_fixtures.py:56: in <module>
class AuthorFactory(factory.Factory):
.tox/py36-pytest3/lib/python3.6/site-packages/pytest_factoryboy/fixture.py:60: in register
deps = get_deps(factory_class, model_name=model_name)
.tox/py36-pytest3/lib/python3.6/site-packages/pytest_factoryboy/fixture.py:154: in get_deps
for attr, value in factory_class.declarations(factory_class._meta.postgen_declarations).items()
E AttributeError: 'FactoryOptions' object has no attribute 'postgen_declarations'
_____________________________ ERROR collecting tests/test_lazy_fixture.py ______________________________
tests/test_lazy_fixture.py:29: in <module>
register(UserFactory)
.tox/py36-pytest3/lib/python3.6/site-packages/pytest_factoryboy/fixture.py:60: in register
deps = get_deps(factory_class, model_name=model_name)
.tox/py36-pytest3/lib/python3.6/site-packages/pytest_factoryboy/fixture.py:154: in get_deps
for attr, value in factory_class.declarations(factory_class._meta.postgen_declarations).items()
E AttributeError: 'FactoryOptions' object has no attribute 'postgen_declarations'
_________________________ ERROR collecting tests/test_postgen_dependencies.py __________________________
tests/test_postgen_dependencies.py:23: in <module>
class FooFactory(factory.Factory):
.tox/py36-pytest3/lib/python3.6/site-packages/pytest_factoryboy/fixture.py:60: in register
deps = get_deps(factory_class, model_name=model_name)
.tox/py36-pytest3/lib/python3.6/site-packages/pytest_factoryboy/fixture.py:154: in get_deps
for attr, value in factory_class.declarations(factory_class._meta.postgen_declarations).items()
E AttributeError: 'FactoryOptions' object has no attribute 'postgen_declarations'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 4 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
======================================= 4 error in 0.30 seconds ========================================
ERROR: InvocationError: '…/Vcs/pytest-factoryboy/.tox/py36-pytest3/bin/py.test --junitxml=…/Vcs/pytest-factoryboy/.tox/py36-pytest3/log/junit-py36-pytest3.xml pytest_factoryboy tests'
_______________________________________________ summary ________________________________________________
ERROR: py36-pytest3: commands failed
Bisecting brings up the following commits (2 are skipped, since they cause a different error):
https://github.com/FactoryBoy/factory_boy/commit/c079d87ddb8e0eeabc66762d7f8f5bb81a143ff0 https://github.com/FactoryBoy/factory_boy/commit/e44766245e70fa102a7e1f85d3bd66c3646d271e https://github.com/FactoryBoy/factory_boy/commit/6f202077a5c8156fe96f8a028f883c14962f5b95
Likely related to the refactoring mentioned in https://github.com/pytest-dev/pytest-factoryboy/issues/23#issuecomment-316717930.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:7
- Comments:5 (1 by maintainers)
Top Results From Across the Web
factory_boy has no attribute 'objects' - django - Stack Overflow
This error basically occuring if your model class is not inherited from the django models.Model. So "objects" is not available.
Read more >Reference — Factory Boy stable documentation
This attribute indicates that the Factory subclass should not be used to generate objects, but instead provides some extra defaults.
Read more >Using factory_boy with ORMs - Read the Docs
When using RelatedFactory or PostGeneration attributes, the base object will be saved once all post-generation hooks have run. class factory.django.
Read more >factory.django — Factory Boy rbarrois-guide documentation
__name__)) try: manager = model_class.objects except AttributeError: # When inheriting from an abstract model with a custom # manager, the class has no...
Read more >factory.declarations — Factory Boy stable documentation
Resolver): The object holding currently computed attributes step: a factory.builder. ... Raises: AttributeError: if obj has no 'name' attribute.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Confirming that this has something to do with 2.9.0 (master) changes alone. I switched to FactoryBoy 2.8.1 and was able to avoid this issue for now.
I decided to ditch pytest-factoryboy and simply write a function that injects the factories as fixtures as-is, per the example in https://github.com/pytest-dev/pytest/issues/2424
So, if your current conftest.py looks like this:
try the following instead:
My current test suite works with it without modifications, and I no longer need pytest-factoryboy as the dependency. Your mileage may vary, so this may not be enough for your needs.