Expose the environment variables used by %pytest via %{py3_test_envvars}
This way, we will be able to reuse them in %tox from pyproject-rpm-macros. Packagers will be able to use them in their spec files. See https://lists.fedoraproject.org/archives/list/python-devel@lists.fedoraproject.org/thread/A3QQSHP5OSLIVMCL52AR2GRBRXYQHU6B/
This commit is contained in:
parent
86c391c493
commit
b647925300
@ -131,6 +131,16 @@
|
||||
end
|
||||
}
|
||||
|
||||
# Environment variables for testing used standalone, e.g.:
|
||||
# %%{py_test_envvars} %%{python} -m unittest
|
||||
%py_test_envvars %{expand:\\\
|
||||
CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}"\\\
|
||||
PATH="%{buildroot}%{_bindir}:$PATH"\\\
|
||||
PYTHONPATH="${PYTHONPATH:-%{buildroot}%{python_sitearch}:%{buildroot}%{python_sitelib}}"\\\
|
||||
PYTHONDONTWRITEBYTECODE=1\\\
|
||||
%{?__pytest_addopts:PYTEST_ADDOPTS="${PYTEST_ADDOPTS:-} %{__pytest_addopts}"}\\\
|
||||
PYTEST_XDIST_AUTO_NUM_WORKERS=%{_smp_build_ncpus}}
|
||||
|
||||
%python_disable_dependency_generator() \
|
||||
%undefine __pythondist_requires \
|
||||
%{nil}
|
||||
|
@ -105,13 +105,16 @@
|
||||
end
|
||||
}
|
||||
|
||||
# This is intended for Python 3 only, hence also no Python version in the name.
|
||||
%__pytest /usr/bin/pytest%(test %{python3_pkgversion} == 3 || echo -%{python3_version})
|
||||
%pytest %{expand:\\\
|
||||
# Environment variables used by %%pytest, %%tox or standalone, e.g.:
|
||||
# %%{py3_test_envvars} %%{python3} -m unittest
|
||||
%py3_test_envvars %{expand:\\\
|
||||
CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}"\\\
|
||||
PATH="%{buildroot}%{_bindir}:$PATH"\\\
|
||||
PYTHONPATH="${PYTHONPATH:-%{buildroot}%{python3_sitearch}:%{buildroot}%{python3_sitelib}}"\\\
|
||||
PYTHONDONTWRITEBYTECODE=1\\\
|
||||
%{?__pytest_addopts:PYTEST_ADDOPTS="${PYTEST_ADDOPTS:-} %{__pytest_addopts}"}\\\
|
||||
PYTEST_XDIST_AUTO_NUM_WORKERS=%{_smp_build_ncpus}\\\
|
||||
%__pytest}
|
||||
PYTEST_XDIST_AUTO_NUM_WORKERS=%{_smp_build_ncpus}}
|
||||
|
||||
# This is intended for Python 3 only, hence also no Python version in the name.
|
||||
%__pytest /usr/bin/pytest%(test %{python3_pkgversion} == 3 || echo -%{python3_version})
|
||||
%pytest %py3_test_envvars %__pytest
|
||||
|
@ -162,6 +162,7 @@ grep -E '^#[^%%]*%%[^%%]' %{buildroot}%{rpmmacrodir}/macros.* && exit 1 || true
|
||||
* Sun Nov 13 2022 Miro Hrončok <mhroncok@redhat.com> - 3.11-6
|
||||
- Set PYTEST_XDIST_AUTO_NUM_WORKERS=%%{_smp_build_ncpus} from %%pytest
|
||||
- pytest-xdist 3+ respects this value when -n auto is used
|
||||
- Expose the environment variables used by %%pytest via %%{py3_test_envvars}
|
||||
|
||||
* Tue Oct 25 2022 Lumír Balhar <lbalhar@redhat.com> - 3.11-5
|
||||
- Include pathfix.py in this package
|
||||
|
@ -357,6 +357,28 @@ def test_pytest_addopts_preserves_envvar(__pytest_addopts):
|
||||
assert 'z--' not in echoed
|
||||
|
||||
|
||||
@pytest.mark.parametrize('__pytest_addopts', ['-X', None])
|
||||
def test_py3_test_envvars(lib, __pytest_addopts):
|
||||
lines = rpm_eval('%{py3_test_envvars}\\\n%{python3} -m unittest',
|
||||
buildroot='BUILDROOT',
|
||||
_smp_build_ncpus='3',
|
||||
__pytest_addopts=__pytest_addopts)
|
||||
assert all(l.endswith('\\') for l in lines[:-1])
|
||||
stripped_lines = [l.strip(' \\') for l in lines]
|
||||
sitearch = f'BUILDROOT/usr/{lib}/python{X_Y}/site-packages'
|
||||
sitelib = f'BUILDROOT/usr/lib/python{X_Y}/site-packages'
|
||||
assert f'PYTHONPATH="${{PYTHONPATH:-{sitearch}:{sitelib}}}"' in stripped_lines
|
||||
assert 'PATH="BUILDROOT/usr/bin:$PATH"' in stripped_lines
|
||||
assert 'CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}"' in stripped_lines
|
||||
assert 'PYTHONDONTWRITEBYTECODE=1' in stripped_lines
|
||||
assert 'PYTEST_XDIST_AUTO_NUM_WORKERS=3' in stripped_lines
|
||||
if __pytest_addopts:
|
||||
assert f'PYTEST_ADDOPTS="${{PYTEST_ADDOPTS:-}} {__pytest_addopts}"' in stripped_lines
|
||||
else:
|
||||
assert 'PYTEST_ADDOPTS' not in ''.join(lines)
|
||||
assert stripped_lines[-1] == '/usr/bin/python3 -m unittest'
|
||||
|
||||
|
||||
def test_pypi_source_default_name():
|
||||
urls = rpm_eval('%pypi_source',
|
||||
name='foo', version='6')
|
||||
@ -691,6 +713,7 @@ unversioned_macros = pytest.mark.parametrize('macro', [
|
||||
'%py_install_egg',
|
||||
'%py_install_wheel',
|
||||
'%py_check_import',
|
||||
'%py_test_envvars',
|
||||
])
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user