Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error output when specifying multiple argument strings with parametrize #8593

Open
The-Compiler opened this issue Apr 26, 2021 · 4 comments
Labels
topic: parametrize related to @pytest.mark.parametrize

Comments

@The-Compiler
Copy link
Member

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 The-Compiler added the topic: parametrize related to @pytest.mark.parametrize label Apr 26, 2021
@The-Compiler
Copy link
Member Author

The-Compiler commented Apr 26, 2021

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.

@RonnyPfannschmidt
Copy link
Member

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

@Yunirang
Copy link

Yunirang commented Apr 7, 2024

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

@RonnyPfannschmidt
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: parametrize related to @pytest.mark.parametrize
Projects
None yet
Development

No branches or pull requests

3 participants