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

missleading error on getfuncargvalue for parameterized fixture #460

Closed
pytestbot opened this Issue Feb 12, 2014 · 13 comments

Comments

Projects
None yet
3 participants
@pytestbot

pytestbot commented Feb 12, 2014

Originally reported by: Nikolaus Rath (BitBucket: nikratio, GitHub: nikratio)


The attached meta-test-case results in

#!

    @pytest.fixture(params=(0,1,2))
    def param1(request):
>       return request.param
E       AttributeError: 'SubRequest' object has no attribute 'param'

with pytest from Mercurial tip.


@pytestbot

This comment has been minimized.

pytestbot commented Jun 23, 2014

Original comment by Matthias Geier (BitBucket: geier, GitHub: geier):


I get the same error when trying to create a fixture that concatenates two or more other fixtures (see my question on stackoverflow).

It's possible to have a fixture using a fixture using a fixture and so on, but it doesn't seem to be possible if parametrized fixtures are involved.

@pytestbot

This comment has been minimized.

pytestbot commented Jun 23, 2014

Original comment by Matthias Geier (BitBucket: geier, GitHub: geier):


Here's my code example (without classes) that shows the same error:

#!python

import pytest

@pytest.fixture(params=[1, 2, 3])
def lower(request):
    return "i" * request.param

@pytest.fixture(params=[1, 2])
def upper(request):
    return "I" * request.param

@pytest.fixture(params=['lower', 'upper'])
def all(request):
    return request.getfuncargvalue(request.param)

def test_all(all):
    assert 0, all

Is there a way to make this work?

@pytestbot

This comment has been minimized.

pytestbot commented Apr 2, 2015

Original comment by Fayaz Khan (BitBucket: fayaz, GitHub: fayaz):


In my case, the fixture seems to be failing because it shares name with a parameter on the test.

#!python

import pytest


@pytest.fixture(params=(0, 1, 2))
def param1(request):
    return request.param


@pytest.mark.parametrize('param1b', (1, 2))
def test_method(param1, param1b):
    assert param1 >= 0

Try changing the name param1b to param2 or something else, and it would work.

@pytestbot

This comment has been minimized.

pytestbot commented May 19, 2015

Original comment by Markus Unterwaditzer (BitBucket: untitaker, GitHub: untitaker):


@Fayaz I have just discovered this issue as well and filed #745 because it doesn't seem to have anything to do with nested fixture requests.

@tomviner

This comment has been minimized.

Contributor

tomviner commented May 19, 2016

@RonnyPfannschmidt any reason this is listed as backward compatibility? Is request.getfuncargvalue deprecated? I'm hitting this issue with an on/off settings flipper fixture being used by a fixture that uses request.getfuncargvalue.

A minimal test case, equivalent of the one above:

import pytest

@pytest.fixture(params=[0])
def fix_with_param(request):
    print request.param

@pytest.fixture
def get_named_fixture(request):
    return request.getfuncargvalue('fix_with_param')

def test_thing(get_named_fixture):
    pass

Result is same as above: AttributeError: 'SubRequest' object has no attribute 'param'

@RonnyPfannschmidt

This comment has been minimized.

Member

RonnyPfannschmidt commented May 19, 2016

that kind of usage should raise an error
'getfuncargvalue` cannnot ever work for parameter requests

@RonnyPfannschmidt RonnyPfannschmidt changed the title from AttributeError: 'SubRequest' object has no attribute 'param' to missleading error on getfuncargvalue for parameterized fixture May 19, 2016

@RonnyPfannschmidt

This comment has been minimized.

Member

RonnyPfannschmidt commented May 19, 2016

this is a rather bad case,
since its also possible to hit this one indirectly

@tomviner

This comment has been minimized.

Contributor

tomviner commented May 24, 2016

Yeah I can see that using getfuncargvalue in a fixture can't start multiplying the cases, like params do. In fact it seems as difficult as supporting unittest subtests (#1367).

I think a better error than AttributeError: 'SubRequest' object has no attribute 'param' would be good.

@RonnyPfannschmidt

This comment has been minimized.

Member

RonnyPfannschmidt commented May 24, 2016

its a completely different dimension than subtests ^^

subtests happen by design within a test

this case is requesting something that should have been parametrized before the test within the test and without parameters

@tomviner

This comment has been minimized.

Contributor

tomviner commented May 24, 2016

Fair enough. But we're agreed on needing a better error message?

@RonnyPfannschmidt

This comment has been minimized.

Member

RonnyPfannschmidt commented May 24, 2016

correct

@tomviner

This comment has been minimized.

Contributor

tomviner commented Jun 25, 2016

Fixed by #1620 Please close.

(I'll do the magic commit message that closes issues next time)

@RonnyPfannschmidt

This comment has been minimized.

Member

RonnyPfannschmidt commented Jun 25, 2016

thanks

fkohlgrueber pushed a commit to fkohlgrueber/pytest that referenced this issue Oct 27, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment