Skip to content

Commit 9a49286

Browse files
ciancbenoit-cty
authored andcommitted
Fixing two tests that fail on Mac:
1. tests/test_cpu_load.py - allow for `AppleSiliconChip` CPU type. 1. tests/test_unsupported_gpu.py - don't bother running this on Mac since NVML is not supported and the test becomes flaky becomes sometimes the AppleSiliconChip GPU power consumption is close enough to zero to pass, and sometimes it isn't.
1 parent 9650f77 commit 9a49286

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

tests/test_cpu_load.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from codecarbon.core.units import Power
66
from codecarbon.emissions_tracker import OfflineEmissionsTracker
7-
from codecarbon.external.hardware import CPU, MODE_CPU_LOAD
7+
from codecarbon.external.hardware import CPU, MODE_CPU_LOAD, AppleSiliconChip
88

99

1010
@mock.patch("codecarbon.core.cpu.is_psutil_available", return_value=True)
@@ -57,7 +57,9 @@ def test_cpu_load_detection(
5757
):
5858
tracker = OfflineEmissionsTracker(country_iso_code="FRA")
5959
for hardware in tracker._hardware:
60-
if isinstance(hardware, CPU) and hardware._mode == MODE_CPU_LOAD:
60+
if (
61+
isinstance(hardware, CPU) and hardware._mode == MODE_CPU_LOAD
62+
) or isinstance(hardware, AppleSiliconChip):
6163
break
6264
else:
6365
raise Exception("No CPU load !!!")

tests/test_unsupported_gpu.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import sys
23
import unittest
34
from unittest.mock import MagicMock, patch
45

@@ -18,6 +19,10 @@ def tearDown(self):
1819
if os.path.exists(self.output_csv):
1920
os.remove(self.output_csv)
2021

22+
# If we run this on macOS, NVMLError_NotSupported has no effect
23+
# and we end up with non-zero valus for GPU energy and power because
24+
# we use the non-NVML code-path in hardware.AppleSiliconChip().
25+
@unittest.skipIf(sys.platform == "darwin", "NVML not available on macOS")
2126
@patch("codecarbon.core.gpu.pynvml")
2227
def test_emissions_tracker_unsupported_gpu(self, mock_pynvml):
2328
mock_pynvml.NVMLError_NotSupported = self.NVMLError_NotSupported

0 commit comments

Comments
 (0)