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
DM-31141: Add test decorators for cartesian product #96
Conversation
b1c569d
to
12288bd
Compare
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.
Looks okay.
python/lsst/utils/tests.py
Outdated
@@ -842,6 +843,112 @@ def wrapper(self, *args, **kwargs): | |||
return decorator | |||
|
|||
|
|||
def cartesianProduct(settings): |
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.
I assume this is a private function that should start with an underscore?
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.
I wouldn't have called it private: it doesn't have any hidden implementation details. It's just a helper function. It doesn't get exported in the __all__
only because I didn't think it would be useful to anyone, but does that make it "private"?
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.
Okay. I tend to put an _
in front of functions as an additional "don't rely on this existing in the future" hint since people can pull functions out of packages even if they aren't in __all__
. Up to you.
""" | ||
product = {kk: [] for kk in settings} | ||
for values in itertools.product(*settings.values()): | ||
for kk, vv in zip(settings.keys(), values): |
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 the keys()
necessary there?
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.
To clarify my comment, I don't think .keys()
is needed because zip
will automatically get the keys from the dict.
>>> a = {1:2, 3:4}
>>> b = {"a":"b", "c":"d"}
>>> print(list(zip(a, b)))
[(1, 'a'), (3, 'c')]
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.
Absolutely. I updated the code already.
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.
👍 I realized my comment was ambiguous such that the thumbs up from you was ambiguous to me 😄
tests/test_decorators.py
Outdated
def testMethodDecorator(self, xx, yy): | ||
self.combinations.add((xx, yy)) | ||
|
||
def teardown_method(self, method): |
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 this pytest-specific?
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.
Ah, it seems it is -- it doesn't fire when run with python tests/test_decorators.py
. I copied the earlier implementation, which also uses it.
Do I need to find an alternative implementation?
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.
It's somewhat ironic that the test of this new decorator that implements functionality already present in pytest, requires pytest to be tested. The test passes when run as python tests/...
or it fails?
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.
It passes. It just doesn't hit this additional check, and so isn't exercising the full test.
I've got an alternative implementation in mind. I'll give it a go.
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.
OK, lemme know what you think of this.
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.
Using a test flag and tearDown
is fine with me.
The classParameters and methodParameters decorators are useful, but sometimes you want to iterate over all combinations of some parameters, but don't want to go to the trouble of listing all combinations. This commit adds classParametersProduct and methodParmaetersProduct that generates the cartesian product of the provided parameters, and iterates over them.
The teardown_method method doesn't fire when run directly, but only under pytest, which means that a developer running the test directly isn't testing the functionality. Adopted an alternative implementation that doesn't rely on pytest. It's heavier than I would like (relies on the method being tested on teardown flipping a switch), but it gets the job done.
12288bd
to
92e40cf
Compare
OK, I think everyone is happy. Merge is imminent. |
No description provided.