Skip to content

test: fix the two remaining Windows unit-test failures (#1460) - #1477

Open
PRINCE2-AI wants to merge 1 commit into
mlco2:masterfrom
PRINCE2-AI:fix/windows-test-portability
Open

PRINCE2-AI wants to merge 1 commit into
mlco2:masterfrom
PRINCE2-AI:fix/windows-test-portability

Conversation

@PRINCE2-AI

@PRINCE2-AI PRINCE2-AI commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes the two Windows failures left in #1460. Both changes are test-only.

1. test_expired_cache_entry_is_refetched (Windows, Python 3.12 and older)

The test patched ELECTRICITYMAPS_CACHE_TTL to 0 and expected the second call to refetch. The cache check is time.monotonic() - cached[0] <= ELECTRICITYMAPS_CACHE_TTL, and on Windows Python 3.12 time.monotonic() uses GetTickCount64() (15.6 ms resolution): two calls inside one tick give a difference of exactly 0, the entry still looks fresh, and the test observes one request instead of two.

The test now moves the module's clock past the TTL instead of shrinking the TTL, so it checks the same "entry older than TTL" contract without depending on clock resolution. The patch replaces the name time in electricitymaps_api's namespace, which leaves the real clock in place for requests and responses.

2. test_task_energy_with_live_update_interference (any machine with an NVIDIA driver)

TestCarbonTracker patched codecarbon.core.gpu.pynvml, but AllGPUDevices and NvidiaGPUDevice read codecarbon.core.gpu_nvidia.pynvml (codecarbon/core/gpu.py:35-38, codecarbon/core/gpu_nvidia.py:54). gpu.pynvml is only a backwards-compatible alias, so on a machine with a driver the test queried real GPU energy and overshot the expected total. The patch now targets the module that is actually read.

Group 1 of #1460 no longer applies: #1462 skips the RAPL tests off Linux.

Fixes #1460.

Verification

  • Before, Windows 11 / Python 3.12 / master ab8627a1, -m "not integ_test", tests/test_viz_data.py excluded because dash is not installed: 871 passed, 1 failed — the failure was test_expired_cache_entry_is_refetched. It also fails on Python 3.11 here.
  • After: tests/test_electricitymaps_cache.py tests/test_emissions_tracker.py → 51 passed.
  • ruff format --check clean on both files. ruff check reports the same 5 pre-existing findings as master, none on a changed line.

I could not reproduce the GPU test locally: this machine has no NVIDIA GPU, so test_task_energy_with_live_update_interference passes either way here. That half follows hifarrer's reproduction in #1460, where patching codecarbon.core.gpu_nvidia.pynvml made it pass on a driver-equipped machine.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

AI Usage Disclosure

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the docs/how-to/contributing.md document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

The cache-expiry test set the TTL to 0, but Windows time.monotonic() has
15.6 ms resolution, so two calls can land in one tick and the entry still
looks fresh. Move the module clock past the TTL instead.

The tracker test patched codecarbon.core.gpu.pynvml, which nothing reads:
AllGPUDevices and NvidiaGPUDevice go through codecarbon.core.gpu_nvidia.pynvml,
so a real driver was queried whenever one was installed.
@PRINCE2-AI
PRINCE2-AI requested a review from a team as a code owner November 7, 2026 19:11
Copilot AI balanced review requested due to automatic review settings November 7, 2026 19:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@github-actions github-actions Bot added the size/S label Nov 7, 2026

This branch has not been deployed

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unit tests on Windows: 13 failures besides the CLI ones in #1459 (one also on any machine with an NVIDIA GPU)

2 participants