From 1f8a088b90b46bf514190d3fe2885e9eb17aa635 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Sat, 26 Jun 2021 16:24:21 +0200 Subject: [PATCH] %pytest: Set $PYTEST_ADDOPTS when %{__pytest_addopts} is defined Related to https://bugzilla.redhat.com/show_bug.cgi?id=1935212 --- macros.python3 | 1 + python-rpm-macros.spec | 6 +++++- tests/test_evals.py | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/macros.python3 b/macros.python3 index 323e675..38fd8e3 100644 --- a/macros.python3 +++ b/macros.python3 @@ -86,4 +86,5 @@ PATH="%{buildroot}%{_bindir}:$PATH"\\\ PYTHONPATH="${PYTHONPATH:-%{buildroot}%{python3_sitearch}:%{buildroot}%{python3_sitelib}}"\\\ PYTHONDONTWRITEBYTECODE=1\\\ + %{?__pytest_addopts:PYTEST_ADDOPTS="${PYTEST_ADDOPTS:-} %{__pytest_addopts}"}\\\ %__pytest} diff --git a/python-rpm-macros.spec b/python-rpm-macros.spec index 20ec1d7..f75c68c 100644 --- a/python-rpm-macros.spec +++ b/python-rpm-macros.spec @@ -22,7 +22,7 @@ License: MIT and Python # The macro is defined in python-srpm-macros. %{?load:%{SOURCE102}} Version: %{__default_python3_version} -Release: 36%{?dist} +Release: 37%{?dist} BuildArch: noarch @@ -95,6 +95,10 @@ install -m 644 compileall2.py %{buildroot}%{_rpmconfigdir}/redhat/ %changelog +* Mon Jun 28 2021 Miro Hrončok - 3.9-37 +- %%pytest: Set $PYTEST_ADDOPTS when %%{__pytest_addopts} is defined +- Related: rhzb#1935212 + * Mon Mar 29 2021 Miro Hrončok - 3.9-36 - Allow commas as argument separator for extras names in %%python_extras_subpkg - Fixes: rhbz#1936486 diff --git a/tests/test_evals.py b/tests/test_evals.py index e2909c3..dff88ba 100644 --- a/tests/test_evals.py +++ b/tests/test_evals.py @@ -199,6 +199,39 @@ def test_pytest_command_suffix(): assert '/usr/bin/pytest-3.6 -v' in lines[-1] +def test_pytest_undefined_addopts_are_not_set(): + lines = rpm_eval('%pytest', __pytest_addopts=None) + assert 'PYTEST_ADDOPTS' not in '\n'.join(lines) + + +def test_pytest_defined_addopts_are_set(): + lines = rpm_eval('%pytest', __pytest_addopts="--ignore=stuff") + assert 'PYTEST_ADDOPTS="${PYTEST_ADDOPTS:-} --ignore=stuff"' in '\n'.join(lines) + + +@pytest.mark.parametrize('__pytest_addopts', ['--macronized-option', 'x y z', None]) +def test_pytest_addopts_preserves_envvar(__pytest_addopts): + # this is the line a packager might put in the spec file before running %pytest: + spec_line = 'export PYTEST_ADDOPTS="--exported-option1 --exported-option2"' + + # instead of actually running /usr/bin/pytest, + # we run a small shell script that echoes the tested value for inspection + lines = rpm_eval('%pytest', __pytest_addopts=__pytest_addopts, + __pytest="sh -c 'echo $PYTEST_ADDOPTS'") + + echoed = shell_stdout('\n'.join([spec_line] + lines)) + + # assert all values were echoed + assert '--exported-option1' in echoed + assert '--exported-option2' in echoed + if __pytest_addopts is not None: + assert __pytest_addopts in echoed + + # assert the options are separated + assert 'option--' not in echoed + assert 'z--' not in echoed + + def test_pypi_source_default_name(): url = rpm_eval('%pypi_source', name='foo', version='6')[0]