(self)
| 369 | |
| 370 | class TestGpuNotAvailable: |
| 371 | def setup_method(self): |
| 372 | self.old_sys_path = copy(sys.path) |
| 373 | fake_module_path = os.path.join(os.path.dirname(__file__), "fake_modules") |
| 374 | sys.path.insert(0, fake_module_path) |
| 375 | |
| 376 | # Clean old modules |
| 377 | try: |
| 378 | del sys.modules["pynvml"] |
| 379 | except KeyError: |
| 380 | pass |
| 381 | |
| 382 | try: |
| 383 | del sys.modules["codecarbon.core.gpu"] |
| 384 | except KeyError: |
| 385 | pass |
| 386 | for module_name in ( |
| 387 | "codecarbon.core.gpu_amd", |
| 388 | "codecarbon.core.gpu_nvidia", |
| 389 | "codecarbon.core.gpu_device", |
| 390 | ): |
| 391 | sys.modules.pop(module_name, None) |
| 392 | |
| 393 | import codecarbon.core |
| 394 | |
| 395 | for attr in ["gpu", "gpu_nvidia", "gpu_amd", "gpu_device"]: |
| 396 | if hasattr(codecarbon.core, attr): |
| 397 | delattr(codecarbon.core, attr) |
| 398 | |
| 399 | import codecarbon.core |
| 400 | |
| 401 | for attr in ["gpu", "gpu_nvidia", "gpu_amd", "gpu_device"]: |
| 402 | if hasattr(codecarbon.core, attr): |
| 403 | delattr(codecarbon.core, attr) |
| 404 | |
| 405 | import pynvml |
| 406 | |
| 407 | pynvml.INIT_MOCK.side_effect = pynvml.NVMLError("NVML Shared Library Not Found") |
| 408 | |
| 409 | def teardown_method(self): |
| 410 | import pynvml |
nothing calls this directly
no outgoing calls
no test coverage detected