-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Allow adding parameter names to auto-generated parametrized test IDs #13106
base: main
Are you sure you want to change the base?
Conversation
Exciting proposal, really helpful for my current work! Have you considered going further? Allow custom parameters for IDs (default is "all") to avoid losing readability when there are too many. Inspired by: https://github.com/yt-dlp/yt-dlp?tab=readme-ov-file#output-template For example:
Or:
|
@dongfangtianyu If you ignore certain parameters, won't the IDs lose their uniqueness? |
caf0530
to
b15cd74
Compare
The CI checks were green before rebasing and seem to happen on the main branch as well. |
Yes, a simple example : non unique IDs will be automatically suffixed: @pytest.mark.parametrize(
"a",
[6,6,6,9,9,9],
)
def test(a):
pass
|
@@ -0,0 +1 @@ | |||
``@pytest.mark.parametrize()`` and ``pytest.Metafunc.parametrize()`` now support the ``id_names`` argument enabling auto-generated test IDs consisting of parameter name=value pairs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first glance, it seems that there are two different functions supporting ids_name
, and perhaps only @pytest.mark.parameterize()
should be show. Additionally, it would be very enticing if you added an example in the changelog, such as: #12492.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since both the mark decorator and the method on Metafunc now support id_names
, I'd like to keep it that way if the maintainers don't have anything against this.
Regarding an example in the changelog: I've added an example to the documentation. Shouldn't that be enough? At least to me the changelog entry pretty much covers the new feature.
To facilitate type checking and autocompletion in the IDE, could you please add the |
Hm, I'm not convinced that such special behavior needs to be offered by So I'd like to keep the PR this way for now. You can always extend the functionality later in a separate PR.
Sure! (edit: done) |
Once the fix is in and this PR gets rebased, hopefully things are all green again! |
By default, only the parameter's values make it into parametrized test IDs. The parameter names don't. Since parameter values do not always speak for themselves, the test function + test ID are often not descriptive/expressive. Allowing parameter name=value pairs in the test ID optionally to get an idea what parameters a test gets passed is beneficial. So add a kwarg `id_names` to @pytest.mark.parametrize() / pytest.Metafunc.parametrize(). It defaults to `False` to keep the auto-generated ID as before. If set to `True`, the argument parameter=value pairs in the auto-generated test IDs are enabled. Calling parametrize() with `ids` and `id_names=True` is considered an error. Auto-generated test ID with `id_names=False` (default behavior as before): test_something[100-10-True-False-True] Test ID with `id_names=True`: test_something[speed_down=100-speed_up=10-foo=True-bar=False-baz=True] Signed-off-by: Bastian Krause <[email protected]>
b15cd74
to
9c12fd6
Compare
I am not sure whether |
By default, only the parameter's values make it into parametrized test IDs. The parameter names don't. Since parameter values do not always speak for themselves, the test function + test ID are often not descriptive/expressive.
Allowing parameter name=value pairs in the test ID optionally to get an idea what parameters a test gets passed is beneficial. So add a kwarg
id_names
to@pytest.mark.parametrize()
/pytest.Metafunc.parametrize()
. It defaults toFalse
to keep the auto-generated ID as before. If set toTrue
, the argument parameter=value pairs in the auto-generated test IDs are enabled. Callingparametrize()
withids
andid_names=True
is considered an error.Auto-generated test ID with
id_names=False
(default behavior as before):Test ID with
id_names=True
:Closes #13055