Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: SubRequest instance has no attribute 'param'

When I run a test with parameters I should be able to access the actual test parameter thought the request's param attribute but instead a got this error:

AttributeError: SubRequest instance has no attribute 'param'

This seems to appear only when I use pytest-bdd test framework. In the following an example of my test fixture:

@pytest.fixture(params=(
    {
        'driver_name': 'remote',
        'url': 'http://x.x.x.x:4444/wd/hub',
        'browser': 'safari',
        'platform': 'MAC'
    },
    {
        'driver_name': 'remote',
        'url': 'http://x.x.x.x:4444/wd/hub',
        'browser': 'chrome',
        'platform': 'MAC'
    }
))
def browser_kwargs(request):
    """Webdriver kwargs."""
    return request.param 

@pytest.fixture
def browser(browser_kwargs):
    """Splinter webdriver"""
    return Browser(**browser_kwargs)
like image 771
Salvatore Avanzo Avatar asked Jun 22 '26 09:06

Salvatore Avanzo


1 Answers

The fix for me was to stop letting my test class inherit from unittest2.TestCase:

class ViewTestSuite(unittest2.TestCase):
    '''Raises error'''

class ViewTestSuite():
    '''No error'''

It seems (though I'm not sure), that in my case, the real culprit was hidden deep inside pytest, and seems to have been the AttributeError:

AttributeError("'TestCaseFunction' object has no attribute 'callspec'",)

caught here, causing param not to be set on request (SubRequest in this case).

like image 82
qff Avatar answered Jun 25 '26 19:06

qff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!