Skip to content

fix(logging): fixed test to actually test#13886

Draft
XrossFox wants to merge 5 commits intoGoogleCloudPlatform:mainfrom
XrossFox:loggin-snippets-test-fixes
Draft

fix(logging): fixed test to actually test#13886
XrossFox wants to merge 5 commits intoGoogleCloudPlatform:mainfrom
XrossFox:loggin-snippets-test-fixes

Conversation

@XrossFox
Copy link
Contributor

@XrossFox XrossFox commented Mar 4, 2026

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

XrossFox and others added 3 commits February 16, 2026 19:04
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
@product-auto-label product-auto-label bot added api: logging Issues related to the Cloud Logging API. samples Issues that are directly related to samples. labels Mar 4, 2026
@XrossFox XrossFox added the kokoro:run Add this label to force Kokoro to re-run the tests. label Mar 4, 2026
@kokoro-team kokoro-team removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Mar 4, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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

  • Improved Test Validation: The tests for logging snippets have been enhanced to actually validate outputs, ensuring that log entries are correctly written and listed.
  • Eventual Consistency Handling: Introduced eventually_consistent_test with backoff in test_write and test_delete to reliably check for log entry presence and deletion in cloud logging, which can be eventually consistent.
  • Simplified Snippet Execution: The if __name__ == "__main__": block in snippets.py was modified to directly call logging functions for easier local testing, bypassing argparse.
Changelog
  • logging/samples/snippets/snippets.py
    • Commented out the argparse command-line argument parsing block.
    • Added direct calls to write_entry, list_entries, and delete_logger for simplified execution within the if __name__ == "__main__": block.
  • logging/samples/snippets/snippets_test.py
    • Modified test_write to include an eventually_consistent_test decorator using backoff to assert that a written log entry appears in the listed entries.
    • Wrapped the delete_logger call in test_delete within an eventually_consistent_test to ensure the deletion is eventually reflected.
  • logging/samples/snippets/usage_guide.py
    • Removed an unnecessary blank line.
    • Commented out the _backoff_not_found(item.delete) call within the main function's cleanup loop.
Activity
  • The author, XrossFox, created this pull request to address issue b/486226544.
  • The author has marked most items in the checklist as complete, indicating adherence to guidelines and passing tests.
  • No other review comments or activity have been recorded yet.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +559 to +560
pass
#_backoff_not_found(item.delete)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
pass
#_backoff_not_found(item.delete)
_backoff_not_found(item.delete)
References
  1. 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.

Comment on lines +47 to +55
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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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.
@XrossFox XrossFox added the kokoro:run Add this label to force Kokoro to re-run the tests. label Mar 4, 2026
@kokoro-team kokoro-team removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Mar 4, 2026
@XrossFox XrossFox added the kokoro:run Add this label to force Kokoro to re-run the tests. label Mar 4, 2026
@XrossFox XrossFox added kokoro:run Add this label to force Kokoro to re-run the tests. and removed kokoro:run Add this label to force Kokoro to re-run the tests. labels Mar 4, 2026
@kokoro-team kokoro-team removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Mar 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: logging Issues related to the Cloud Logging API. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants