[ENG-177] Auto-detect test runs#39
Conversation
Summary of ChangesHello @safaricd, 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 introduces a robust mechanism to automatically detect when the application's code is running within a test environment. The primary purpose is to ensure that telemetry is automatically disabled in such scenarios, preventing test data from polluting production analytics. This change enhances the reliability of telemetry data by isolating it from development and testing activities. Highlights
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 introduces a mechanism to automatically detect when the code is running in a test environment to disable telemetry. The implementation in _runs_in_test is comprehensive, checking environment variables, imported modules, and command-line arguments. The accompanying tests are a good start, but have a few issues.
My review focuses on two main points. First, a potential IndexError in _runs_in_test if sys.argv is empty, which could crash the application in certain environments. I've suggested a fix for this. Second, several tests for the sys.argv check are flawed because they don't isolate the logic under test, leading to false positives. I've provided an explanation and a suggested fix for these tests. Addressing these points will make the new feature more robust and the tests more reliable.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…_utils into detect-test-runs
brendan-priorlabs
left a comment
There was a problem hiding this comment.
Code itself looks good. Two questions for you,
- Were you able to do some manual testing to validate this change? Your callout on module load order in the description was a good one, so I'm curious how well this works in practice.
- I thought we already had some exclusions for test environments. Did that get removed earlier somehow?
| Returns: | ||
| bool: True if telemetry is enabled, False otherwise. | ||
| """ | ||
| # Overwrite any telemetry if running in tests |
There was a problem hiding this comment.
nit: typo, overwrite -> override
Yes, absolutely. It was manually tested inside
We had, using the |
brendan-priorlabs
left a comment
There was a problem hiding this comment.
Makes sense, thanks!
Change Description
Automatically test whenever code runs in a test environment and disable all telemetry.
Known limitations
There are a few limitations we must be aware of with this approach:
_runs_in_testruns beforepytest/unittestis imported, thesys.modulescheck can give a false negative.unittestor evenpytest(for tooling or assertions), which would make this returnTrueeven though we aren't testing.