python-pytest-cases
python-pytest-cases copied to clipboard
`tests\cases\issues\test_issue_269.py` raises ValueError during collection
tests\cases\issues\test_issue_269.py
throws an exception during collection in most test environments with the following trace (modulo the env name)
.nox\tests-3-9-env-pytest-latest\lib\site-packages\pluggy\_hooks.py:433: in __call__
return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
.nox\tests-3-9-env-pytest-latest\lib\site-packages\pluggy\_manager.py:112: in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
.nox\tests-3-9-env-pytest-latest\lib\site-packages\_pytest\python.py:271: in pytest_pycollect_makeitem
return list(collector._genfunctions(name, obj))
.nox\tests-3-9-env-pytest-latest\lib\site-packages\_pytest\python.py:498: in _genfunctions
self.ihook.pytest_generate_tests.call_extra(methods, dict(metafunc=metafunc))
.nox\tests-3-9-env-pytest-latest\lib\site-packages\pluggy\_hooks.py:489: in call_extra
return self._hookexec(self.name, hookimpls, kwargs, firstresult)
.nox\tests-3-9-env-pytest-latest\lib\site-packages\pluggy\_manager.py:112: in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
.nox\tests-3-9-env-pytest-latest\lib\site-packages\_pytest\fixtures.py:1577: in pytest_generate_tests
metafunc.parametrize(
.nox\tests-3-9-env-pytest-latest\lib\site-packages\pytest_cases\plugin.py:910: in parametrize
raise ValueError("This should not happen - please file an issue")
E ValueError: This should not happen - please file an issue
Indeed I am able to reproduce, thanks @jgersti for reporting !
The issue is due to the fact that our own version of MetaFunc.parametrize
is not patched onto the metafunc
object early enough, and another plugin (my fake version of the pytest-repeat
plugin used in tests) has already called the function.
this should be called first:
https://github.com/smarie/python-pytest-cases/blob/ab3b7190d728b18512141b9f5f3a1c3dfc7cedf2/src/pytest_cases/plugin.py#L851-L862
this should be called last:
https://github.com/smarie/python-pytest-cases/blob/ab3b7190d728b18512141b9f5f3a1c3dfc7cedf2/tests/pytest_extension/issues/test_issue_269.py#L10-L26
But unfortunately the opposite happens.
This seems to come from a change in pluggy
that changed the meaning of the try_first
trylast
and wrapper
meanings. Most probably a bug I'd guess. I'll open an issue there.
Issue opened: https://github.com/pytest-dev/pluggy/issues/441 Until the fix is available, we can mark the test as expected to fail.
EDIT : I commented the whole tests/pytest_extension/issues/test_issue_269.py
test file, let's uncomment it when ok