Uh oh!
There was an error while loading. Please reload this page.
Convert logging usage doctests to testable snippets - #2556
Conversation
dhermes
left a comment
There was a problem hiding this comment.
@jonparrott Can you also peek at these?
| do_something_with(entry) | ||
| if token is None: | ||
| break | ||
| entries, token = logger.list_entries(page_token=token) # API request |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| # [END logger_list_entries] | ||
| to_delete.remove(logger) | ||
| backoff = [1, 2, 4, 8] |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| filter_=FILTER, description=DESCRIPTIION) | ||
| assert not new_metric.exists() # API request | ||
| new_metric.create() # API request | ||
| assert new_metric.exists() # API request |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| except AssertionError as e: | ||
| print(' FAIL: %s' % (e,)) | ||
| except Exception as e: # pylint: disable=broad-except | ||
| print(' ERROR: %r' % (e,)) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
theacodes
left a comment
There was a problem hiding this comment.
This looks okay to me as a start, but it is concerning to see so much setup/cleanup logic in the snippet function body. Pytest fixtures can help a lot with that, or just having separate test functions for each snippet. We do both in python-docs-samples.
Fixture example from @pytest.fixturedefexample_log():
client=logging.Client()
logger=client.logger(TEST_LOGGER_NAME)
text='Hello, world.'logger.log_text(text)
returntextThis looks pretty nice! |
@tseaver Here is a proof of concept for running readable interpreter snippets without worrying about calling First, create a fake module (or any object really) with our content in the >>>importtypes>>>fake_mod=types.ModuleType('haha-nope')
>>>fake_mod.__doc__="""\... Here is some prose, and then a dragon appears... and it makes sure division::...... >>> a = 45... >>> a / 3... 15...... and then the bunny hops down the lane and we... find out we have to print a null::...... >>> b = {}... >>> v = b.get('anything')... >>> v... >>> print(v)... None... """then hand that object off to >>>importdoctest>>>fake_globals= {}
>>>doctest.run_docstring_examples(fake_mod, fake_globals, verbose=False, name='foo')
>>>doctest.run_docstring_examples(fake_mod, fake_globals, verbose=True, name='foo')
FindingtestsinfooTrying:
a=45ExpectingnothingokTrying:
a/3Expecting:
15okTrying:
b= {}
ExpectingnothingokTrying:
v=b.get('anything')
ExpectingnothingokTrying:
vExpectingnothingokTrying:
print(v)
Expecting:
Noneok |
Toward #212 / #2535.