question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pytest-factoryboy do not work with pytest 3.0

See original GitHub issue

When 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:closed
  • Created 7 years ago
  • Reactions:5
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
thedrowcommented, Sep 11, 2016
0reactions
prmtlcommented, Nov 16, 2016

#32 solved this problem indeed. I’m closing.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found