Skip to content

Commit 01927d4

Browse files
committed
TST: enable fatal meson warnings for all tests, unless explicitly disabled
This uses a pytest ``autouse`` fixture to monkeypatch the function that validates the ``pyproject.toml`` meson-python configuration to add ``--fatal-meson-warnings`` to the ``meson setup`` arguments, unless ``--no-fatal-meson-warnings`` is specified by the package.
1 parent 0444e63 commit 01927d4

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

tests/conftest.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5+
import argparse
56
import contextlib
67
import importlib.metadata
78
import os
@@ -192,3 +193,31 @@ def cleanenv():
192193
# $MACOSX_DEPLOYMENT_TARGET affects the computation of the platform tag on macOS.
193194
yield mpatch.delenv('MACOSX_DEPLOYMENT_TARGET', raising=False)
194195
mpatch.undo()
196+
197+
198+
@pytest.fixture(autouse=True, scope='session')
199+
def meson_fatal_warnings():
200+
# Cannot use the 'monkeypatch' fixture because of scope mismatch.
201+
mpatch = pytest.MonkeyPatch()
202+
mesonpy_validate_pyproject_config = mesonpy._validate_pyproject_config
203+
204+
def _validate_pyproject_config(pyproject):
205+
pyproject_config = mesonpy_validate_pyproject_config(pyproject)
206+
207+
meson_args = pyproject_config.setdefault('args', {})
208+
meson_setup_args = meson_args.get('setup', [])
209+
210+
# Add ``--fatal-meson-warnings`` to the ``meson setup`` arguments
211+
# unless the project specifies ``--no-fatal-meson-warnings`` in
212+
# ``tool.meson-build.args.setup``.
213+
parser = argparse.ArgumentParser(add_help=False)
214+
parser.add_argument('--no-fatal-meson-warnings', action='store_true')
215+
meson_setup_args = meson_args.get('setup', [])
216+
args, meson_setup_args = parser.parse_known_args(meson_setup_args)
217+
if not args.no_fatal_meson_warnings:
218+
meson_setup_args.append('--fatal-meson-warnings')
219+
meson_args['setup'] = meson_setup_args
220+
221+
return pyproject_config
222+
223+
mpatch.setattr(mesonpy, '_validate_pyproject_config', _validate_pyproject_config)

tests/test_project.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ def test_ios_project(package_simple, monkeypatch, multiarch, tmp_path):
399399
project = mesonpy.Project(source_dir=package_simple, build_dir=tmp_path)
400400

401401
# Meson configuration points at the cross file
402-
assert project._meson_args['setup'] == ['--cross-file', os.fspath(tmp_path / 'meson-python-cross-file.ini')]
402+
assert project._meson_args['setup'][-2:] == ['--cross-file', os.fspath(tmp_path / 'meson-python-cross-file.ini')]
403403

404404
# Meson config files exist, and have some relevant keys
405405
assert (tmp_path / 'meson-python-native-file.ini').exists()

0 commit comments

Comments
 (0)