Refactor: Mock OpenAI calls in job analyzer tests - #6
Open
frenzel-ai-dev wants to merge 4 commits into
Open
Conversation
I've separated the OpenAI API-dependent test into an integration test. - I modified `tests/test_job_analyzer.py` to ensure all tests use `unittest.mock` for OpenAI API calls. - I created `tests/integration/test_job_analyzer_integration.py` and moved the test that makes actual API calls (`test_full_analysis_process`) into it. - This integration test is marked with `@pytest.mark.integration` and requires the `OPENAI_API_KEY` environment variable to be set to pass. Unit tests in `tests/test_job_analyzer.py` now all pass with mocks. The integration test in `tests/integration/test_job_analyzer_integration.py` will pass if a valid `OPENAI_API_KEY` is available in the environment.
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the job analyzer test suite by removing the real-API integration test from the unit tests and moving it into its own integration test file.
- All unit tests in
tests/test_job_analyzer.pynow mock OpenAI API calls. - A separate integration test in
tests/integration/test_job_analyzer_integration.pyexercises the full analysis process with real API calls (marked with@pytest.mark.integration).
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| tests/test_job_analyzer.py | Removed the @pytest.mark.integration test, ensuring all unit tests mock OpenAI API calls. |
| tests/integration/test_job_analyzer_integration.py | Added a new integration test file that runs the full CLI analysis with real OpenAI API calls. |
| @@ -0,0 +1,63 @@ | |||
| import os | |||
There was a problem hiding this comment.
The import 'os' is unused; if you're planning to check OPENAI_API_KEY, consider adding a skip guard using os.getenv, otherwise remove the import.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I've separated the OpenAI API-dependent test into an integration test.
tests/test_job_analyzer.pyto ensure all tests useunittest.mockfor OpenAI API calls.tests/integration/test_job_analyzer_integration.pyand moved the test that makes actual API calls (test_full_analysis_process) into it.@pytest.mark.integrationand requires theOPENAI_API_KEYenvironment variable to be set to pass.Unit tests in
tests/test_job_analyzer.pynow all pass with mocks. The integration test intests/integration/test_job_analyzer_integration.pywill pass if a validOPENAI_API_KEYis available in the environment.