Skip to content

Commit 4cfa597

Browse files
authored
tests: support make missing (#140)
Support missing make when running tests. Signed-off-by: Henry Schreiner <[email protected]>
1 parent b3baca6 commit 4cfa597

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

tests/test_fileapi.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
from __future__ import annotations
22

3+
import os
4+
import shutil
5+
import sys
36
from pathlib import Path
47

58
import pytest
@@ -14,6 +17,21 @@
1417

1518
DIR = Path(__file__).parent.absolute()
1619

20+
has_make = shutil.which("make") is not None or shutil.which("gmake") is not None
21+
has_ninja = shutil.which("ninja") is not None
22+
23+
24+
def prepare_env_or_skip() -> None:
25+
if (
26+
"CMAKE_GENERATOR" not in os.environ
27+
and not sys.platform.startswith("win32")
28+
and not has_make
29+
):
30+
if has_ninja:
31+
os.environ["CMAKE_GENERATOR"] = "Ninja"
32+
else:
33+
pytest.skip("No build system found")
34+
1735

1836
@pytest.mark.configure
1937
def test_cattrs_comparison(tmp_path):

tests/test_simple_pure.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
import os
4+
import shutil
35
import subprocess
46
import sys
57
from pathlib import Path
@@ -12,8 +14,26 @@
1214
DIR = Path(__file__).parent.absolute()
1315

1416

17+
has_make = shutil.which("make") is not None or shutil.which("gmake") is not None
18+
has_ninja = shutil.which("ninja") is not None
19+
20+
21+
def prepare_env_or_skip() -> None:
22+
if (
23+
"CMAKE_GENERATOR" not in os.environ
24+
and not sys.platform.startswith("win32")
25+
and not has_make
26+
):
27+
if has_ninja:
28+
os.environ["CMAKE_GENERATOR"] = "Ninja"
29+
else:
30+
pytest.skip("No build system found")
31+
32+
1533
@pytest.fixture(scope="session")
1634
def config(tmp_path_factory):
35+
prepare_env_or_skip()
36+
1737
tmp_path = tmp_path_factory.mktemp("build")
1838

1939
build_dir = tmp_path / "build"
@@ -72,6 +92,8 @@ def test_install(config):
7292

7393
@pytest.mark.configure
7494
def test_variable_defined(tmp_path, capfd):
95+
prepare_env_or_skip()
96+
7597
build_dir = tmp_path / "build"
7698

7799
cmake = CMake.default_search(minimum_version=Version("3.15"))

0 commit comments

Comments
 (0)