Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pytest-lazy-fixture breaks with Traits in factoryboy 3.2.0: 'Maybe' object has no attribute 'call' #52

Open
radekwlsk opened this issue May 13, 2021 · 3 comments

Comments

@radekwlsk
Copy link

radekwlsk commented May 13, 2021

After updating factoryboy to 3.2.0 my tests using lazy_fixture with fixtures that use Trait (in result using Maybe) raise AttributeError: 'Maybe' object has no attribute 'call'.

python_version = "3.8"
django = "~=3.0"
factory-boy = "~=3.2.0"
pytest = "~=5.4.3"
pytest-factoryboy = "~=2.1.0"
pytest-lazy-fixture = "~=0.6.3"

Attached is a full traceback from failed test case.

request = <FixtureRequest for <Function test_success>>

    def fill(request):
        item = request._pyfuncitem
        fixturenames = getattr(item, "fixturenames", None)
        if fixturenames is None:
            fixturenames = request.fixturenames
    
        if hasattr(item, 'callspec'):
            for param, val in sorted_by_dependency(item.callspec.params, fixturenames):
                if val is not None and is_lazy_fixture(val):
                    item.callspec.params[param] = request.getfixturevalue(val.name)
                elif param not in item.funcargs:
                    item.funcargs[param] = request.getfixturevalue(param)
    
>       _fillfixtures()

/home/django/venv/lib/python3.8/site-packages/pytest_lazyfixture.py:39: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/home/django/venv/lib/python3.8/site-packages/pytest_factoryboy/fixture.py:188: in model_fixture
    factoryboy_request.evaluate(request)
/home/django/venv/lib/python3.8/site-packages/pytest_factoryboy/plugin.py:83: in evaluate
    self.execute(request, function, deferred)
/home/django/venv/lib/python3.8/site-packages/pytest_factoryboy/plugin.py:65: in execute
    self.results[model][attr] = function(request)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

request = <SubRequest 'user' for <Function test_success>>

    def deferred(request):
>       declaration.call(instance, step, context)
E       AttributeError: 'Maybe' object has no attribute 'call'

/home/django/venv/lib/python3.8/site-packages/pytest_factoryboy/fixture.py:294: AttributeError

Seems like it could be a problem in pytest_factoryboy itself but I've seen it raised only for tests using lazy_fixture.

@TvoroG
Copy link
Owner

TvoroG commented May 13, 2021

Hey! Can you show minimal example of broken test?

Thanks for opening the issue!

@MRigal
Copy link

MRigal commented Jun 22, 2021

@MRigal
Copy link

MRigal commented Jun 24, 2021

The problem doens't come frompytest-lazy-fixture but from pytest-factoryboy, see this PR for failing tests pytest-dev/pytest-factoryboy#125

Update: It looks like it comes from pytest-lazy-fixture because the plugin is calling the _fillfixtures method/fixture first. So it is triggering the behaviour which would happen else a bit later anyway

I think @TvoroG you can close this issue (and if you want help to fix the issue on the pytest-factoryboy side)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants