Skip to content

test: fix forecast csv mock target - #363

Open
timothykou wants to merge 1 commit into
openclimatefix:mainfrom
timothykou:fix/forecast-csv-mock-target
Open

test: fix forecast csv mock target#363
timothykou wants to merge 1 commit into
openclimatefix:mainfrom
timothykou:fix/forecast-csv-mock-target

Conversation

@timothykou

Copy link
Copy Markdown

Pull Request

Description

Addresses #231.

This is a small test-only follow-up to the slow CI/unit-test investigation. tests/unit/test_generate_forecast.py already tried to mock run_forecast, but it patched quartz_solar_forecast.forecast.run_forecast. The code under test imports run_forecast directly into quartz_solar_forecast.utils.forecast_csv, so the mock did not intercept the call and the unit test still exercised the real forecast path.

This changes the test to patch quartz_solar_forecast.utils.forecast_csv.run_forecast, which is the symbol actually used by write_out_forecasts.

Performance / CI relevance:

  • Before this change, local instrumentation showed test_generate_forecast made 5 live Open-Meteo calls.
  • After this change, the same test passes with Open-Meteo calls: 0.
  • The targeted test body is reported by pytest as 0.01s with --durations=0.

This intentionally does not try to solve all of #231 in one PR. Other unit tests still make live Open-Meteo calls, so this is a narrow first step rather than a full closure.

How Has This Been Tested?

uv sync
.venv/bin/python -m ruff check tests/unit/test_generate_forecast.py
.venv/bin/python -m pytest tests/unit/test_generate_forecast.py::test_generate_forecast -q --durations=0

Results:

  • Ruff: All checks passed!
  • Targeted pytest: 1 passed; slowest call 0.01s
  • Guard check with openmeteo_requests.Client.weather_api patched to fail: 1 passed, Open-Meteo calls: 0

I also ran the full unit suite with a local requests-cache==1.3.2 override because current main is affected by the separate requests-cache==1.2.0 issue:

uv pip install requests-cache==1.3.2
.venv/bin/python -m pytest tests/unit -q --durations=15

Result: 22 passed, 4 warnings in 171.77s. The suite is still slow because other unit tests continue to call live weather APIs; those should be addressed separately.

  • Yes

Checklist:

  • My code follows OCF's coding style guidelines
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation - not needed for this test-only fix
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked my code and corrected any misspellings

@timothykou

Copy link
Copy Markdown
Author

CI note: the visible red branch_ci / test-unit (3.11) check was cancelled, and before cancellation the log shows the pull_request_target workflow checked out refs/remotes/origin/main, not this PR branch. The regular fork pull_request workflow is action_required, likely waiting for maintainer approval. This PR's targeted local verification is in the PR body; the failing/cancelled unit check is not a clean result for this branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant