-
Notifications
You must be signed in to change notification settings - Fork 193
Enforce working examples in docstrings and documentation #1588
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
base: main
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
1a46a09 to
5fe8ece
Compare
5fe8ece to
a23907e
Compare
| counter = logfire.metric_counter( | ||
| 'exceptions', | ||
| unit='1', # (1)! | ||
| description='Number of exceptions caught' |
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.
Add a comma at the end here to keep the args on separate lines, especially so that # (1)! stays on the unit arg. same for others below.
| #> Failed to execute query. Status code: 401 | ||
| print(response.text) | ||
| #> {"detail":"Invalid token"} |
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.
| #> Failed to execute query. Status code: 401 | |
| print(response.text) | |
| #> {"detail":"Invalid token"} | |
| print(response.text) |
this is being skipped, right?
|
|
||
|
|
||
| def capture_response_headers(span: Span, response: Union[TraceRequestEndParams, TraceRequestExceptionParams]): | ||
| def capture_response_headers(span: Span, response: TraceRequestEndParams | TraceRequestExceptionParams): |
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.
| def capture_response_headers(span: Span, response: TraceRequestEndParams | TraceRequestExceptionParams): | |
| def capture_response_headers(span: Span, response: 'TraceRequestEndParams | TraceRequestExceptionParams'): |
then skip the future import?
| #> 019b38289f5dfbf64cd7de68d37c6a04 | ||
| ``` | ||
|
|
||
| will print something like: |
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.
Let's not have both this and the comments above
| print('Serving on port 8000...') | ||
| #> Serving on port 8000... |
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.
| print('Serving on port 8000...') | |
| #> Serving on port 8000... |
|
|
||
| # Override the autouse fixtures from conftest.py to prevent them from | ||
| # interfering with doc examples. Doc examples call their own logfire.configure() | ||
| # and we don't want them to pollute the test exporter state. |
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 don't see how the test exporter state would get polluted. are you sure this fixture is needed?
Require formatted and runnable examples in docstrings and documentation, and bring the documentation and code up to compliance with these new requirements. Closes #1587
Uses
pytest-examplesto ensure that examples in docstrings and documentation are properly formatted and runnable with assertions on anyprintstatements in the example. Addspytest-timeoutto the dev dependencies which is used to prevent example tests from running forever if they hit blocking code.There are zero lines of actual code changed outside the
test_docs.py. The majority of the PR is imports organization, linting, formatting, and ensuring that examples are runnable or ensuring we skip examples that should not be linted or that should not be run (either because they are incomplete examples, require internet access or an external connection, or are blocking).There are ~300 newly passing tests and ~140 skipped tests (examples that are not checked for formatting or if they are runnable).