-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
49 lines (34 loc) · 1.37 KB
/
conftest.py
File metadata and controls
49 lines (34 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from __future__ import annotations
from typing import TYPE_CHECKING
import pytest
from ttsim.interface_dag_elements.backend import dnp as ttsim_dnp
from ttsim.interface_dag_elements.backend import xnp as ttsim_xnp
if TYPE_CHECKING:
from types import ModuleType
from typing import Literal
def pytest_addoption(parser):
parser.addoption(
"--backend",
action="store",
default="numpy",
help="The backend to test against (e.g., --backend=numpy --backend=jax)",
)
@pytest.fixture
def backend(request) -> Literal["numpy", "jax"]:
return request.config.getoption("--backend")
@pytest.fixture
def xnp(request) -> ModuleType:
return ttsim_xnp(request.config.getoption("--backend"))
@pytest.fixture
def dnp(request) -> ModuleType:
return ttsim_dnp(request.config.getoption("--backend"))
@pytest.fixture(autouse=True)
def skipif_jax(request, backend):
"""Automatically skip tests marked with skipif_jax when backend is jax."""
if request.node.get_closest_marker("skipif_jax") and backend == "jax":
pytest.skip("Cannot run this test with Jax")
@pytest.fixture(autouse=True)
def skipif_numpy(request, backend):
"""Automatically skip tests marked with skipif_numpy when backend is numpy."""
if request.node.get_closest_marker("skipif_numpy") and backend == "numpy":
pytest.skip("Cannot run this test with Numpy")