Repository navigation
[MRG+1] Pytest parametrize unit tests (part 1) - ensemble module - #11075
Conversation
jnothman
left a comment
There was a problem hiding this comment.
I suppose there are alternative ways to express the same thing, e.g. with fixtures. But this looks fine to me
Yes, you are right, let me see if expressing the frequent parametrizations (here |
|
I don't think it's essential, but if we're trying to establish an idiom, we
might as well try get it right.
|
Yes, I agree that it would be helpful if we could agree on on some convention regarding how tests should ideally be parametrized with pytest in scikit-learn. @lesteve @qinhanmin2014 @amueller @glemaitre For instance, below is an example of pytest parametrized test, FOREST_CLASSIFIERS = {
"ExtraTreesClassifier": ExtraTreesClassifier,
"RandomForestClassifier": RandomForestClassifier,
}
@pytest.mark.parametrize('name', FOREST_CLASSIFIERS)
def test_some_assumption(name):
check_some_assumption(name)it is also possible to express the same thing with a fixture, @pytest.fixture(params=FOREST_CLASSIFIERS)
def forest_classifiers_fixture(request):
return request.param
def test_some_assumption(forest_classifiers_fixture):
check_some_assumption(forest_classifiers_fixture)when the same parametrization is often used (as is the case in this PR) this might allow to write things of more consisely. However,
This PR is an example of using WDYT? |
|
lgtm.com seems to be down.. Another (unrelated) question cc @lesteve is that
So the question is should I put these |
|
I think |
Thanks for the feedback and the review! Well, it's not that much extra work... Also, to be specific, this discussion is only about using fixtures for parametrizations. There are other use cases, where fixtures would definitely make sense IMO, such as loading test datasets (or making random datasets) once and distributing it to all tests that need those. I wonder if by reducing I/O this way tests won't run faster, but that would require a separate investigation.. |
|
@lesteve would you have an opinion about #11075 (comment) ? |
|
ping @glemaitre in case you have any opinion on the test style in #11075 (comment) In the end, this PR doesn't break backward compatibility for nose based decorators to skip tests in Otherwise, it has enough approvals to press the green button ) |
|
I am checking soonish :)
…On 16 May 2018 at 17:37, Roman Yurchak ***@***.***> wrote:
ping @glemaitre <https://github.com/glemaitre> in case you have any on
the test style in #11075 (comment)
<#11075 (comment)>
In the end, this PR doesn't break backward compatibility for nose based
decorators to skip tests in sklearn/utils/testing.py (related to #11075
(comment)
<#11075 (comment)>)
I guess we discuss deprecating that later.
Otherwise, it has enough approval to press the green button )
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#11075 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHG9P1LoaffsF2LRgdqiB5dt5o64JlXjks5tzEecgaJpZM4T1Foy>
.
--
Guillaume Lemaitre
INRIA Saclay - Parietal team
Center for Data Science Paris-Saclay
https://glemaitre.github.io/
|
glemaitre
left a comment
There was a problem hiding this comment.
I have a single nitpick.
Regarding #11075 (comment), I am not sure that we should care about deprecation there. When making contribution (as imblearn) we were force to use nose anyway until 0.19. I am not sure that forcing pytest would be actually an issue, IMO.
| FOREST_ESTIMATORS.update(FOREST_REGRESSORS) | ||
| FOREST_ESTIMATORS.update(FOREST_TRANSFORMERS) | ||
|
|
||
| FOREST_CLASSIFIERS_REGRESSORS = dict(FOREST_CLASSIFIERS, **FOREST_REGRESSORS) |
There was a problem hiding this comment.
I got a bit surprise here. Apparently this is a cool hack (maybe not the best to have it in the code base since it working only with key string cf.). I would use update or a dict comprehension.
There was a problem hiding this comment.
Yes, I wasn't aware that was so much debate online about the right way to merge dicts in Python (see https://stackoverflow.com/a/26853961/1791279). I did like this version but since it's controversial, reverted it to a simpler one. As a side note, as args expansion related hacks go you might like this one which I have seen used in practice )
|
Thanks for the feedback! Addressed your comments. Also following your suggestion replaced the nose specific |
jnothman
left a comment
There was a problem hiding this comment.
What should I be checking? I'm not entirely sure we should be changing utils/testing.py, but I can hope no one's relied on it that is not using pytest...?
|
@jnothman just the diff related to True; to summarize,
|
|
I mean those functions are only used for testing. So the worst case scenario even if someone was relying on them, is that
So in general I think it's a week reason to keep unused code in the code base.. |
|
okay, I'm fine with the changes
|
|
Thanks rth!!! |
|
Nice ! |
|
Learnt a lot from the nice work! |
Reference Issues/PRs
This is Part 1 of #11074
Please refer to the parent PR for general description and comments.