-
-
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
Extend _pytest.python._idval to return __name__ of functions as well #2976
Conversation
… not just for classes
This should probably go to the |
Thanks @st-- for the PR! Agree with @The-Compiler, changed the target to |
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.
Please add a test for it to avoid future regressions.
Hadn't written a test because most of the other cases of _idval didn't have any, either. Happy to add one - I guess in testing/python/metafunc.py ? Should I add one for the isclass() case as well while I'm at it? |
Both suggestions sound good, thanks! |
Test added, travis passed :) |
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.
Great, thank you!
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!!