%pytest: Set $PYTEST_ADDOPTS when %{__pytest_addopts} is defined

Related to https://bugzilla.redhat.com/show_bug.cgi?id=1935212

Related: rhbz#1950291
This commit is contained in:
Miro Hrončok 2021-06-28 09:34:10 +00:00
parent 9235955bb3
commit 1232cc253e
3 changed files with 38 additions and 1 deletions

View File

@ -86,4 +86,5 @@
PATH="%{buildroot}%{_bindir}:$PATH"\\\ PATH="%{buildroot}%{_bindir}:$PATH"\\\
PYTHONPATH="${PYTHONPATH:-%{buildroot}%{python3_sitearch}:%{buildroot}%{python3_sitelib}}"\\\ PYTHONPATH="${PYTHONPATH:-%{buildroot}%{python3_sitearch}:%{buildroot}%{python3_sitelib}}"\\\
PYTHONDONTWRITEBYTECODE=1\\\ PYTHONDONTWRITEBYTECODE=1\\\
%{?__pytest_addopts:PYTEST_ADDOPTS="${PYTEST_ADDOPTS:-} %{__pytest_addopts}"}\\\
%__pytest} %__pytest}

View File

@ -1,6 +1,6 @@
Name: python-rpm-macros Name: python-rpm-macros
Version: 3.9 Version: 3.9
Release: 39%{?dist} Release: 40%{?dist}
Summary: The common Python RPM macros Summary: The common Python RPM macros
URL: https://src.fedoraproject.org/rpms/python-rpm-macros/ URL: https://src.fedoraproject.org/rpms/python-rpm-macros/
@ -96,6 +96,9 @@ install -m 644 compileall2.py %{buildroot}%{_rpmconfigdir}/redhat/
%changelog %changelog
* Mon Jun 28 2021 Miro Hrončok <mhroncok@redhat.com> - 3.9-40
- %%pytest: Set $PYTEST_ADDOPTS when %%{__pytest_addopts} is defined
* Tue Jun 15 2021 Miro Hrončok <mhroncok@redhat.com> - 3.9-39 * Tue Jun 15 2021 Miro Hrončok <mhroncok@redhat.com> - 3.9-39
- Fix %%python_provide when fed python3.10-foo to obsolete python-foo instead of python--foo - Fix %%python_provide when fed python3.10-foo to obsolete python-foo instead of python--foo

View File

@ -211,6 +211,39 @@ def test_pytest_command_suffix():
assert '/usr/bin/pytest-3.6 -v' in lines[-1] 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(): def test_pypi_source_default_name():
urls = rpm_eval('%pypi_source', urls = rpm_eval('%pypi_source',
name='foo', version='6') name='foo', version='6')