TvoroG / pytest-lazy-fixture

It helps to use fixtures in pytest.mark.parametrize
MIT License
377 stars 30 forks source link

TypeError: 'LazyFixture' object is not subscriptable #58

Open flazzarini opened 2 years ago

flazzarini commented 2 years ago

Hi there,

I was trying to do the following code which results in a Exception being thrown. I was wondering if someone has found a way to use the returned object from a lazy_fixture in the parametrize values

import pytest
from pytest_lazyfixture import lazy_fixture

@pytest.fixture
def one():
    return {
        "foo1": "bar",
        "foo2": "baz",
    }

@pytest.mark.parametrize(
    'attr1',
    [
        (lazy_fixture('one')["foo1"], ),
    ]
)
def test_func(attr1):
    assert attr1 == "bar"
============================================================================================================= test session starts =============================================================================================================
platform linux -- Python 3.10.5, pytest-7.1.3, pluggy-1.0.0
rootdir: /home/users/frank/workspace/pseudopiper, configfile: pytest.ini
plugins: xdist-2.5.0, cov-4.0.0, lazy-fixture-0.6.3, clarity-1.0.1, icdiff-0.6, forked-1.4.0
collected 0 items / 1 error

=================================================================================================================== ERRORS ====================================================================================================================
___________________________________________________________________________________________________ ERROR collecting tests/test_foobar2.py ____________________________________________________________________________________________________
tests/test_foobar2.py:14: in <module>
    (lazy_fixture('one')["foo1"], ),
E   TypeError: 'LazyFixture' object is not subscriptable
=========================================================================================================== short test summary info ===========================================================================================================
ERROR tests/test_foobar2.py - TypeError: 'LazyFixture' object is not subscriptable
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================================================================================== 1 error in 0.21s ===============================================================================================================