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
Conversation
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).
aee1dab
to
e7b99e1
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.
This looks great.
python/lsst/utils/tests.py
Outdated
Note that the values are embedded in the class name. | ||
""" | ||
def decorator(cls): | ||
num = len(next(iter(settings.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.
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.
5bb6cc6
to
105d512
Compare
""" | ||
num = len(next(iter(settings.values()))) # Number of settings | ||
for name, values in settings.items(): | ||
if isinstance(values, str): |
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 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.
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.
Well spotted! I've pushed a fix.
No description provided.