/
/
/
1"""Test that numba compiles its kernels into a cache private to this test process."""
2
3from __future__ import annotations
4
5import os
6from typing import TYPE_CHECKING
7
8from numba.core import config as numba_config
9
10from tests.conftest import NUMBA_CACHE_DIR
11
12if TYPE_CHECKING:
13 import pytest
14
15
16def test_numba_kernel_cache_is_process_private(pytestconfig: pytest.Config) -> None:
17 """Verify numba caches its compiled kernels in a directory this process owns alone."""
18 # a TemporaryDirectory of this session's own, so no other process can be writing there
19 assert os.environ["NUMBA_CACHE_DIR"] == pytestconfig.stash[NUMBA_CACHE_DIR].name
20 # numba snapshots the variable as it is imported, so a mismatch means it got in first
21 # (numba ships type info only on newer versions, where CACHE_DIR is set at runtime)
22 assert os.environ["NUMBA_CACHE_DIR"] == numba_config.CACHE_DIR # type: ignore[attr-defined, unused-ignore]
23