fix(logging): fixed test to actually test#13886
fix(logging): fixed test to actually test#13886XrossFox wants to merge 5 commits intoGoogleCloudPlatform:mainfrom
Conversation
Removal of appengine/flexible_python37_and_earlier path for deprecation. As per my search on Code Search, there are no samples using these deprecated code snippets anymore. b/475332253
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly improves the reliability and effectiveness of the testing suite for Google Cloud Logging Python snippets. The primary goal is to ensure that tests accurately validate the output and behavior of logging operations by incorporating robust checks for eventual consistency when writing, listing, and deleting log entries. This enhancement provides more dependable validation of the sample code's functionality. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request aims to fix tests to make them actually validate outputs. The changes in snippets_test.py are a good step in that direction, making test_write and test_delete more meaningful. However, I've found some issues with the implementation of test_write that could be improved for clarity and correctness. Additionally, as noted in the comments, the changes in snippets.py and usage_guide.py appear to be temporary debugging code that disable core functionality and cleanup mechanisms. These should be reverted before merging to keep the pull request focused on its intended purpose of fixing tests.
| pass | ||
| #_backoff_not_found(item.delete) |
There was a problem hiding this comment.
The cleanup logic for resources created during the run has been commented out. This will lead to resource leaks, especially if this code is used in automated tests. This change should be reverted to ensure proper cleanup. Pull requests should be focused on a single change to simplify the review process.
| pass | |
| #_backoff_not_found(item.delete) | |
| _backoff_not_found(item.delete) |
References
- To simplify the review process, pull requests should be focused on a single change. It is acceptable to defer related changes in other files to subsequent pull requests.
| def test_write(example_log, capsys): | ||
| snippets.write_entry(TEST_LOGGER_NAME) | ||
| @backoff.on_exception(backoff.expo, AssertionError, max_time=120) | ||
| def eventually_consistent_test(): | ||
| snippets.list_entries(TEST_LOGGER_NAME) | ||
| out, _ = capsys.readouterr() | ||
| assert example_log in out | ||
|
|
||
| eventually_consistent_test() |
There was a problem hiding this comment.
The test_write function is intended to test snippets.write_entry, but it uses the example_log fixture which already writes the log entry being asserted. This means the test would pass even if snippets.write_entry did nothing. To properly test write_entry, the test should be self-contained and verify what write_entry itself has written, without relying on a fixture that pre-populates the data.
| def test_write(example_log, capsys): | |
| snippets.write_entry(TEST_LOGGER_NAME) | |
| @backoff.on_exception(backoff.expo, AssertionError, max_time=120) | |
| def eventually_consistent_test(): | |
| snippets.list_entries(TEST_LOGGER_NAME) | |
| out, _ = capsys.readouterr() | |
| assert example_log in out | |
| eventually_consistent_test() | |
| def test_write(capsys): | |
| snippets.write_entry(TEST_LOGGER_NAME) | |
| @backoff.on_exception(backoff.expo, AssertionError, max_time=120) | |
| def eventually_consistent_test(): | |
| snippets.list_entries(TEST_LOGGER_NAME) | |
| out, _ = capsys.readouterr() | |
| assert "Hello, world!" in out | |
| assert "Goodbye, world!" in out | |
| assert "King Arthur" in out | |
| eventually_consistent_test() |
- Updated requirements. - Changed fixture in snippets test.
Took the liberty to make the tests actually validate outputs.
Fixes b/486226544
Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.
Checklist
nox -s py-3.9(see Test Environment Setup)nox -s lint(see Test Environment Setup)