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-22199: Add decorators for iterating over tests #76

Merged
merged 3 commits into from Nov 18, 2019

Conversation

PaulPrice
Copy link
Contributor

No description provided.

If you don't specify an exception, generally you want to catch any
exception, so it should default to Exception rather than AssertionError
(a test failure).
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.

This looks great.

Note that the values are embedded in the class name.
"""
def decorator(cls):
num = len(next(iter(settings.values())))
Copy link
Member

Choose a reason for hiding this comment

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

There is a lot going on in this function with lots of lengths turning up so some commentary would be nice. Maybe "Number of elements in first parameter provided"? I think that if you call this with a str value that is not a list you will end up with the length of the string as this num so we probably want to handle that nicely since they probably made a mistake rather than expecting a test class for each letter.

We often iterate over multiple values in tests. We have been writing this
iteration explicitly, which is annoying (for classes, this involves
subclassing; for methods, this means the values that caused a failure
aren't clear unless special efforts are made). These decorators handle
the iteration for the user, making it much easier to write and understand
tests.
"""
num = len(next(iter(settings.values()))) # Number of settings
for name, values in settings.items():
if isinstance(values, str):
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you have to do this as a separate loop, first. If the first item in settings is a string, num will get set to the length of that string instead of 1 and will then trigger the assertion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well spotted! I've pushed a fix.

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

3 participants