pytest
pytest copied to clipboard
Improve error output when specifying multiple argument strings with parametrize
I started giving more and more pytest trainings recently, and noticed a confusion almost everyone stumbles over when using parametrize the first time. Many people accidentally write:
import pytest
@pytest.mark.parametrize("arg1", "arg2", [(1, 1)])
def test_parametrization(arg1, arg2):
assert arg1 == arg2
i.e. they use "arg1", "arg2" instead of "arg1, arg2" or ("arg1", "arg2") for parametrize. This results in:
In test_parametrization: indirect fixture '(1, 1)' doesn't exist
which is an error message which will confuse newcomers even more (they probably have no idea what an indirect fixture is supposed to be at this point).
We should really try to somehow improve that message, maybe be suggesting the right usage?
I guess we could validate that indirect is really of the expected type (either a bool or a list of strings) - but maybe we should deprecate calling parametrize with indirect, ids or scope as positional arguments (similarly to what we did with fixtures)? I think almost nobody is using them this way, and making those keyword-only would certainly help a lot for situations like this.
@The-Compiler i agree, indirect, ids and scope should migrate to kwonly soon
@RonnyPfannschmidt This is 3 years ago, but do you happen to know if the migrations happened?
As the issue is open, the transition didn't happen