-
Notifications
You must be signed in to change notification settings - Fork 305
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
_TimedContextManagerDecorator enter -> self #147
Conversation
Have _TimedContextManagerDecorator return self from __enter__ so that it can be modified within the block. e.g. with timed('foo.bar', tags=['key:val']) as timer: # do some stuff if blip: timer.tags.append('result:blip') This can be worked around by assigning timed's result to a var and then doing a `with timer`, but this is much cleaner.
Thanks for the change @ross. I'll review the changes this week, and have it out with the next release by the end of the following week 🚢 . |
@@ -313,7 +313,9 @@ def test_timed_context(self): | |||
Measure the distribution of a context's run time. | |||
""" | |||
# In seconds | |||
with self.statsd.timed('timed_context.test'): | |||
with self.statsd.timed('timed_context.test') as timer: | |||
self.assertIsInstance(timer, |
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 need to update the tests to inherit from unittest
. In the meantime would you mind using
t.assert_is_instance(...)
rather than
self.assertIsIstance(...)
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.
Done.
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.
Almost 😄 it should be t.assert...
rather than self.assert...
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.
Interesting. I've haven't run across nose.tools
being used before. Should be in place now.
🙇 |
Have
_TimedContextManagerDecorator
returnself
from__enter__
so that it can be modified within the block. e.g.This can be worked around by assigning timed's result to a var and then doing a
with timer
, but this is much cleaner and shouldn't result in any backwards compatibility issues.