|
| 1 | +import pathlib |
1 | 2 | import subprocess |
2 | 3 | import sys |
3 | 4 |
|
4 | 5 | import pytest |
5 | 6 |
|
6 | 7 | import mesonpy |
7 | 8 |
|
8 | | -from .conftest import build_project_wheel, examples_dir |
| 9 | +from .conftest import chdir |
9 | 10 |
|
10 | 11 |
|
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' |
13 | 13 |
|
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) |
18 | 14 |
|
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