Skip to content
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

Merged
merged 2 commits into from Jul 27, 2021

Conversation

PaulPrice
Copy link
Contributor

No description provided.

Copy link
Member

@timj timj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks okay.

@@ -842,6 +843,112 @@ def wrapper(self, *args, **kwargs):
return decorator


def cartesianProduct(settings):
Copy link
Member

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?

Copy link
Contributor Author

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"?

Copy link
Member

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):
Copy link
Member

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?

Copy link
Member

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')]

Copy link
Contributor Author

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.

Copy link
Member

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 😄

def testMethodDecorator(self, xx, yy):
self.combinations.add((xx, yy))

def teardown_method(self, method):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this pytest-specific?

Copy link
Contributor Author

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?

Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Member

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.
@PaulPrice
Copy link
Contributor Author

OK, I think everyone is happy. Merge is imminent.

@PaulPrice PaulPrice merged commit 5b7b756 into master Jul 27, 2021
@PaulPrice PaulPrice deleted the tickets/DM-31141 branch July 27, 2021 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants