#102 %pytest: Set $PYTEST_ADDOPTS when %{__pytest_addopts} is defined
Merged 2 years ago by churchyard. Opened 2 years ago by churchyard.
rpms/ churchyard/python-rpm-macros pytest_addopts  into  rawhide

file modified
+1
@@ -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}

file modified
+5 -1
@@ -31,7 +31,7 @@ 

  end

  }

  Version:        %{__default_python3_version}

- Release:        2%{?dist}

+ Release:        3%{?dist}

  

  BuildArch:      noarch

  
@@ -109,6 +109,10 @@ 

  

  

  %changelog

+ * Mon Jun 28 2021 Miro Hrončok <mhroncok@redhat.com> - 3.10-3

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

+ - Related: rhzb#1935212

+ 

  * Tue Jun 15 2021 Miro Hrončok <mhroncok@redhat.com> - 3.10-2

  - Fix %%python_provide when fed python3.10-foo to obsolete python-foo instead of python--foo

  

file modified
+33
@@ -211,6 +211,39 @@ 

      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():

      urls = rpm_eval('%pypi_source',

                      name='foo', version='6')

The change looks good to me and I've verified that it fixes the issue I've recently met in the python-build package. See: https://copr.fedorainfracloud.org/coprs/lbalhar/build/builds/

rebased onto d905710

2 years ago

I'll CI test this over all branches before merging.

Build failed. More information on how to proceed and troubleshoot errors available at https://fedoraproject.org/wiki/Zuul-based-ci

Build succeeded.

Pull-Request has been merged by churchyard

2 years ago