Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở Phù hợp với người mới
#1,460 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@dilipna đang làm issue này rồi.

Từ ngày 28/10/2026.

  • #1468 của @dilipna — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
76/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
testing

Hướng nghiên cứu

Bắt đầu với tests/test_rapl_mmio_scanning.py, tests/test_electricitymaps_cache.py và tests/test_emissions_tracker.py; issue mô tả các trường hợp bị lỗi và những cách sửa được đề xuất chỉ dành cho kiểm thử. Đọc các dấu skip Linux liên quan, bước kiểm tra TTL của cache và thiết lập mock GPU. Sau đó chạy các tệp kiểm thử bị ảnh hưởng trên Windows và, với trường hợp GPU, dùng trình điều khiển NVIDIA. Hoàn thành khi 13 lỗi được báo cáo đã được sửa và các kiểm thử chạy thành công.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Running the unit tests locally on Windows 11 (Python 3.12, master 24ddb59a, -m 'not integ_test') gives 773 passed, 15 failed, 20 skipped. Two of the 15 are the CLI tests that #1459 fixes (with #1459 applied, tests/cli passes here: 78 passed). CI runs on Linux without a GPU, so the other 13 don't show up there. They fall into three groups, each with a test-only fix that I checked on this machine.

1. Eleven RAPL tests create folders named intel-rapl:0

_make_rapl_tree creates intel-rapl:{index} directories. : is not allowed in Windows file names, so mkdir raises NotADirectoryError: [WinError 267] The directory name is invalid (the same character problem as #79). These tests set sys.platform to "linux" with monkeypatch, while the other RAPL tests in the same file and in test_rapl_parameters.py and test_rapl_permissions.py are skipped off Linux with:

@pytest.mark.skipif(not sys.platform.lower().startswith("lin"), reason="requires Linux")

Adding the same marker would skip them on Windows and change nothing on Linux.

The 11 failing tests (tests/test_rapl_mmio_scanning.py)
  • test_rapl_start_flags_only_nonzero_mirrored_package_counters (3 cases)
  • test_rapl_start_keeps_dram_when_it_matches_a_package_counter
  • test_rapl_start_skips_unreadable_counters
  • test_rapl_start_reevaluates_mirror_candidates
  • test_rapl_confirmed_mirror_is_dropped_after_identical_deltas
  • test_rapl_coincidental_match_is_restored_after_diverging_deltas
  • test_rapl_mirrors_near_counter_wrap_are_still_detected
  • test_rapl_candidate_with_skipped_sample_stays_pending
  • test_rapl_inconclusive_candidate_stays_pending
2. test_expired_cache_entry_is_refetched (Python 3.12 on Windows)

The test patches ELECTRICITYMAPS_CACHE_TTL to 0 and expects the second call to refetch, but the cache check is time.monotonic() - cached[0] <= ELECTRICITYMAPS_CACHE_TTL. On Windows, Python 3.12's time.monotonic() uses GetTickCount64() (resolution 15.6 ms), so two calls within one tick give a difference of exactly 0 and the cached value is returned: 1 request instead of 2. Python 3.13 switched to QueryPerformanceCounter() (0.1 µs), so I'd expect this only on 3.12. Patching the TTL to -1 instead of 0 makes the test independent of the clock; with that change the file passes here (10 passed, 3 runs).

3. test_task_energy_with_live_update_interference (any machine with an NVIDIA driver)

The total energy exceeds the expected 0.00015 kWh by 1.6e-6 to 3.1e-6 kWh depending on the run. The difference is gpu_energy, measured from this laptop's real GPU (gpu_model in the result is the RTX 3050 Ti). TestCarbonTracker patches codecarbon.core.gpu.pynvml with fake_pynvml, but codecarbon/core/gpu.py calls NVML through gpu_nvidia.pynvml, which that patch does not replace, so the test reaches the real driver when one is installed. Adding

@mock.patch("codecarbon.core.gpu_nvidia.pynvml", fake_pynvml)

to the class makes this test pass here, and all 39 tests in tests/test_emissions_tracker.py still pass with it. I expect the same failure on Linux with an NVIDIA GPU, but I only ran it on Windows.

I can send these three changes as one test-only PR if that's useful.

(Checked and drafted with an AI assistant, Claude Code, and reviewed by me.)

Ngôn ngữ chính
Python
Star
1.9k
Fork
347
Merge trung bình
2 ngày 13 giờ
Pull request đã merge (30 ngày)
20

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của mlco2/codecarbon

Tất cả issue của mlco2/codecarbon

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.