pytest icon indicating copy to clipboard operation
pytest copied to clipboard

Improve error output when specifying multiple argument strings with parametrize

Open The-Compiler opened this issue 4 years ago • 4 comments

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?

The-Compiler avatar Apr 26 '21 12:04 The-Compiler

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 avatar Apr 26 '21 21:04 The-Compiler

@The-Compiler i agree, indirect, ids and scope should migrate to kwonly soon

RonnyPfannschmidt avatar Apr 26 '21 21:04 RonnyPfannschmidt

@RonnyPfannschmidt This is 3 years ago, but do you happen to know if the migrations happened?

Yunirang avatar Apr 07 '24 23:04 Yunirang

As the issue is open, the transition didn't happen

RonnyPfannschmidt avatar Apr 08 '24 04:04 RonnyPfannschmidt