pytest-factoryboy do not work with pytest 3.0
See original GitHub issueWhen trying to use pytest-factoryboy
with newest pytest, exception occurs:
____________________________________________________________________ ERROR at setup of test_asdf ____________________________________________________________________
request = <SubRequest 'xyz' for <Function 'test_asdf'>>, factory_name = 'xyz_factory'
def model_fixture(request, factory_name):
"""Model fixture implementation."""
factoryboy_request = request.getfuncargvalue("factoryboy_request")
# Try to evaluate as much post-generation dependencies as possible
factoryboy_request.evaluate(request)
factory_class = request.getfuncargvalue(factory_name)
prefix = "".join((request.fixturename, SEPARATOR))
data = {}
for argname in request._fixturedef.argnames:
if argname.startswith(prefix) and argname[len(prefix):] not in factory_class._meta.postgen_declarations:
data[argname[len(prefix):]] = request.getfuncargvalue(argname)
class Factory(factory_class):
@classmethod
def attributes(cls, create=False, extra=None):
return dict(
(key, evaluate(request, value))
for key, value in super(Factory, cls).attributes(create=create, extra=extra).items()
if key in data
)
Factory._meta.postgen_declarations = {}
Factory._meta.exclude = [value for value in Factory._meta.exclude if value in data]
# Extract post-generation context
post_decls = []
if factory_class._meta.postgen_declarations:
for attr, decl in sorted(factory_class._meta.postgen_declarations.items()):
post_decls.append((attr, decl, decl.extract(attr, data)))
# Create model fixture instance
instance = Factory(**data)
request._fixturedef.cached_result = (instance, None, None)
> request._fixturedefs[request.fixturename] = request._fixturedef
E AttributeError: SubRequest instance has no attribute '_fixturedefs'
<snip>/lib/python2.7/site-packages/pytest_factoryboy/fixture.py:200: AttributeError
Issue Analytics
- State:
- Created 7 years ago
- Reactions:5
- Comments:6 (2 by maintainers)
Top Results From Across the Web
pytest-lazy-fixture breaks with Traits in factoryboy 3.2 ... - GitHub
After updating factoryboy to 3.2.0 my tests using lazy_fixture with fixtures ... fixturenames): if val is not None and is_lazy_fixture(val): ...
Read more >Welcome to pytest-factoryboy's documentation! — pytest ...
Library exports a function to register factories as fixtures. Fixtures are contributed to the same module where register function is called. Factory Fixture¶....
Read more >In FactoryBoy, how do I setup my factory with an empty many ...
The fix is to change if extracted to if extracted is not None . Explanation. In Python, an empty list is falsey 1...
Read more >pytest-factoryboy - PyPI
pytest -factoryboy makes it easy to combine factory approach to the test setup with the dependency injection, heart of the pytest fixtures.
Read more >Factory injection, combining pytest with factory_boy
Factory injection, combining pytest with factory_boy. The most annoying in writing tests is the setup. All this boilerplate requires so much ...
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
See this build result as an example: https://travis-ci.org/pytest-dev/pytest-factoryboy/jobs/159127349
#32 solved this problem indeed. I’m closing.