-
-
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
[WIP/RFC] parametrize: support dicts #5850
Conversation
TODO: - [ ] link to issue where this was discussed - [ ] doc
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.
While I'm personally oppose to this expression mechanism, it's still of great value to way too many people
we should be careful about the semantics
testing/python/metafunc.py
Outdated
|
||
@pytest.mark.parametrize('arg1,arg2,expected_id', { | ||
"myid_12": [1, 2, "[myid_12]"], | ||
"ignored_id": pytest.param(3, 4, "[myid_34]", id="myid_34"), |
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.
We should always warn and use the dict imposed id
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.
Is a warning really useful/necessary?
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.
This will help in situations with mixed aliasing
The warning cam be skipped if the id is equal or none
We should provide a utility method to drop the id explicitly if necessary
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.
This will help in situations with mixed aliasing
Can you elaborate, please?
I think the typical use case is not to use pytest.param
here in the first place anyway.
The warning cam be skipped if the id is equal or none
Sure, but still I think people might actually be more annoyed by the warning then.
Which I think leads to you thinking about:
We should provide a utility method to drop the id explicitly if necessary
How/where would that be used then? Isn't _replace
good enough?
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.
aliasing -> when reusing predeclared param instances that already have a id, potentially a different one
the warning is absolutely necessary to have an api you cant misuse/misunderstand
a internal method generated by a implementation detail is never enough
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.
aliasing -> when reusing predeclared param instances that already have a id, potentially a different one
Do you have a real-world use case / scenario for this?
the warning is absolutely necessary to have an api you cant misuse/misunderstand
Well, ok - requires to unroll the loop again though (which is ok).
What should be used here warnings
or pytest.warn
?
We should provide a utility method to drop the id explicitly if necessary
How/where would that be used then? Isn't
_replace
good enough?
a internal method generated by a implementation detail is never enough
You mean _replace
is not enough? (it is documented for named tuples, but you mean that us using NamedTuple is the detail?!)
However, how should the method work? Where is the id dropped? (currently it gets replaced (i.e. dropped) always (from the existing paramset))
Do you mean there should be a way to keep it? (i.e. not use the one from the dict)
I don't see why this is necessary when we already have |
especially since dictionary order is still undefined in at least one of the versions we support (python3.5, provisional but dependable in python3.6) |
Well, that should be ok in most cases, and is certainly in the responsibility of the user then. |
FWIW I'm -1 on this as well, because it's IMHO not intuitive that those are test IDs. I first thought this would make it possible to do |
So a dict with arnames and keys, and their values in a list? (where you have a single one now)
Keep in mind that this is meant for advanced usage only, where you like to have custom ids. I think it's a nice way of mapping the id to the used values. How could this be expressed better after all then with a dict? |
TBH I'm also 👎 on the idea... it is not really obvious at first glance what it means. We should probably strive to get away from builtin structures unless when they are absolutely straightforward. Another point is that we already have two methods: the traiditional (argnames, argvalues), and the new pytest.param. I wouldn't like to add a third unless it is a clear win. |
Ok - will keep this in my local "fork" then also I guess. Do you all use For a workaround: you can use dicts already indirectly (#5487 (comment)) - this is what I was doing before, but is rather verbose/indirect then. |
Rejected in pytest-dev#5850.
Rejected in pytest-dev#5850.
Bit late to the party, but 👍 on the suggestion, sad it'd been rejected... Given general ergonomics of pytest and without scanning the docs in much detail one might expect that something like this should "just work" - because:
So we have a collection of params each uniquely identified by a unique id, what's the ideal data structure?... There just happens to be one already built-in. As noted above, it may not be the most extensible way of doing it and may indeed lead to ambiguity in certain edge cases, but I believe it would've improved ergonomics in the majority of typical cases where you have to assign tons of custom ids, as currently you have a choice of either:
|
TODO:
argvalues
forparametrize
#5487 (comment))