Skip to content

Commit 47363b5

Browse files
committed
TST: fix and simplify tests for example project
Build the project and the wheel in a temporary directory. Fixes #169.
1 parent 9d50638 commit 47363b5

File tree

4 files changed

+19
-50
lines changed

4 files changed

+19
-50
lines changed

tests/docs/__init__.py

Whitespace-only changes.

tests/docs/examples/__init__.py

Whitespace-only changes.

tests/docs/examples/conftest.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

tests/test_examples.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
1+
import pathlib
12
import subprocess
23
import sys
34

45
import pytest
56

67
import mesonpy
78

8-
from .conftest import build_project_wheel, examples_dir
9+
from .conftest import chdir
910

1011

11-
def test_build_and_import(venv, tmp_path_session):
12-
"""Test that the wheel for the spam example builds, installs, and imports."""
12+
examples_dir = pathlib.Path(__file__).parent.parent / 'docs' / 'examples'
1313

14-
if sys.version_info < (3, 8):
15-
# The test project requires Python >= 3.8.
16-
with pytest.raises(mesonpy.MesonBuilderError, match=r'Unsupported Python version `3.7.\d+`'):
17-
build_project_wheel(package=examples_dir / 'spam', outdir=tmp_path_session)
1814

19-
else:
20-
wheel = build_project_wheel(package=examples_dir / 'spam', outdir=tmp_path_session)
21-
22-
subprocess.run(
23-
[venv.executable, '-m', 'pip', 'install', wheel],
24-
check=True)
25-
output = subprocess.run(
26-
[venv.executable, '-c', 'import spam; print(spam.add(1, 2))'],
27-
check=True, stdout=subprocess.PIPE).stdout
28-
29-
assert int(output) == 3
15+
def test_spam(venv, tmp_path):
16+
"""Test that the wheel for the example builds, installs, and imports."""
17+
with chdir(examples_dir / 'spam'):
18+
if sys.version_info < (3, 8):
19+
# The test project requires Python >= 3.8.
20+
with pytest.raises(mesonpy.MesonBuilderError, match=r'Unsupported Python version `3.7.\d+`'):
21+
mesonpy.build_wheel(tmp_path)
22+
else:
23+
wheel = mesonpy.build_wheel(tmp_path)
24+
subprocess.run(
25+
[venv.executable, '-m', 'pip', 'install', tmp_path / wheel],
26+
check=True)
27+
output = subprocess.run(
28+
[venv.executable, '-c', 'import spam; print(spam.add(1, 2))'],
29+
check=True, stdout=subprocess.PIPE).stdout
30+
assert int(output) == 3

0 commit comments

Comments
 (0)