Extend _pytest.python._idval to return __name__ of functions as well #2976
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I want to parametrize over factory functions, which I believe is a valid use-case. At the moment, the autogenerated id for the test name is then based on the argument name, plus counter to disambiguate (e.g. feature_factory0, feature_factory1, etc.). With this PR, the default behavior for functions will be the same as for classes: return the
__name__
. I think this is a more sensible default behaviour.Semi-pseudocode example:
As Kernel1, Kernel2, Kernel3 are classes, currently, the tests would be named as follows:
With this PR, the test names would be:
This allows you to immediately figure out which factory function is being used, and doesn't hide the fact that "feature_factory0" and "feature_factory1" are the same thing.
I hope you'll be happy to merge this :-)
PS: Pytest is great, thanks!!