-
Notifications
You must be signed in to change notification settings - Fork 31
Fix loading DC_API_KEY from .env for validation and isolate testing environment #131
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
Conversation
Summary of ChangesHello @clincoln8, 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 addresses an issue where the DC_API_KEY was not reliably loaded from .env files, particularly when the CLI was executed from a different directory than where the application was installed. It introduces the python-dotenv library to ensure correct loading of environment variables from the current working directory. Furthermore, it significantly improves the robustness and reliability of the test suite by implementing global environment isolation for all tests and refactoring test fixtures for better maintainability and clarity. 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.
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 effectively addresses the issue of loading the DC_API_KEY from .env files by integrating python-dotenv. The introduction of global test fixtures in conftest.py is a significant improvement for test hermeticity and maintainability, successfully isolating test environments from the host system. The refactoring to centralize the isolated_env fixture and remove duplicates is also a welcome cleanup. I've added a couple of suggestions to further refine the new test code by removing some redundancy and improving conciseness.
|
/gemini review |
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.
Code Review
This pull request is a great improvement, especially with the introduction of global test environment isolation in conftest.py. This makes the test suite much more robust and hermetic. The changes to load the .env file from the current working directory are also correctly implemented and tested. I have a few minor suggestions in test_cli.py to improve consistency with the new testing patterns and to simplify one of the end-to-end tests.
|
/gemini review |
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.
Code Review
This pull request significantly improves the project's testing infrastructure and fixes an important bug in environment variable loading. The introduction of a global clean_env fixture to ensure hermetic tests is an excellent change that will improve test reliability. The standardization of environment variable mocking across the test suite is also a great cleanup. The fix for loading the .env file from the current working directory is correctly implemented. I have one suggestion to make a test assertion more specific, but overall, this is a high-quality contribution.
|
/gemini review |
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.
Code Review
This is an excellent pull request that significantly improves the project's testing infrastructure and fixes an important bug in environment variable loading. The introduction of the clean_env autouse fixture is a great step towards fully hermetic tests, and the standardization of environment variable patching across test files improves consistency and readability. The new tests for the CLI are thorough and well-written. I have one minor suggestion to make one of the new tests even cleaner by leveraging the new fixture setup.
keyurva
left a comment
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.
Thanks!
| @pytest.fixture(autouse=True) | ||
| def clean_env(tmp_path, monkeypatch): | ||
| """ | ||
| Automatically clear environment variables and change to a temporary directory |
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.
nice!
Ensures .env files are correctly loaded for API key validation using load_dotenv from
cwdand establishes global environment isolation for hermetic testing.Key Changes
.envLoading: Updatedcli.pyto ensureload_dotenvrespects the current working directory when resolving.envfiles.clean_envautouse fixture intests/conftest.pythat clears environment variables and changes the working directory to a temporary path for every test. This ensures tests are hermetic and do not accidentally read the host's.envfile.test_cli.py,test_settings.py,test_dc_client.py, andtest_temp_constrained_vars.pyto consistently use thewith mock.patch.dict(os.environ, ...):context manager pattern.Will bump version to a new RC in a subsequent PR.