Open lucapton opened 1 year ago
Good catch @lucapton ! Looking at the source code, this is...normal :(
This is because my current code in _unpack_fixture
only reuses the original fixture's scope if the provided source fixture is a fixture symbol.
When it is a string it uses 'function' scope. It does not try to ask pytest's fixture manager for help.
But fixing this would anyway not help in your situation, since the fixture a
is not created yet when _unpack_fixture
is called:
https://github.com/smarie/python-pytest-cases/blob/main/src/pytest_cases/fixture_core2.py#L410
So as a workaround I suggest to
_unpack_fixture
to support an explicit scope: str = None
argument, that would be used to override the scope explicitly when provided_decorate_fixture_plus
so that the scope is actually explicitly passed to _unpack_fixture
when unpack_into
is non-noneWould you like to try this in a PR ? Otherwise, I'll do it one of these days, this seems fairly straightforward so that I can squeeze it into my agenda.
I'm not familiar with the inner workings of pytest nor pytest_cases, so I don't think I can afford the time to do the PR, as much as I'd like to.
I want to clarify that pytest_cases.unpack_into("a1, a2", a)
is a perfect workaround for the desired result I wanted. Still, the fact that fixtures created through pytest_cases.fixture(scope=x, unpack_into="y, z")
don't have scope x
but instead always function
tripped me up for a while so I wanted to share both the issue and the workaround.
Very clear @lucapton , thanks! I'll see what I can do one of these days
The example below causes a
ScopeMismatch
error despite everything beingsession
scoped.results in:
If you directly call
pytest_cases.unpack_into("a1, a2", a)
instead of the argument inpytest_cases.fixture
, then there there is no issue asa1
anda2
are correctly scoped tosession
instead offunction
.I'm getting these results using python 3.8.10, pytest 7.2.2, and pytest_cases 3.6.14 in an Ubuntu 20.04 docker container.