Name: pytest
%global base_version 8.2.0
#global prerelease ...
Version: %{base_version}%{?prerelease:~%{prerelease}}
Release: %autorelease
Summary: Simple powerful testing with Python
License: MIT
URL: https://pytest.org
Source: %{pypi_source pytest %{base_version}%{?prerelease}}
# Remove -s from Python shebang,
# ensure that packages installed with pip to user locations are testable
# https://bugzilla.redhat.com/2152171
%undefine _py3_shebang_s
# When building pytest for the first time with new Python version
# we might not yet have all the BRs, those conditionals allow us to do that.
# This can be used to disable all tests for faster bootstrapping.
# The tests are enabled by default except when building on RHEL/ELN
# (to avoid pulling in extra dependencies into next RHEL).
%bcond tests %{undefined rhel}
# Only disabling the optional tests is a more complex but careful approach
# Pytest will skip the related tests, so we only conditionalize the BRs
%bcond optional_tests %{with tests}
# To run the tests in %%check we use pytest-timeout
# When building pytest for the first time with new Python version
# that is not possible as it depends on pytest
%bcond timeout %{with tests}
# When building pytest for the first time with new Python version
# we also don't have sphinx yet and cannot build docs.
# The docs are enabled by default except when building on RHEL/ELN
# (to avoid pulling in extra dependencies into next RHEL).
%bcond docs %{undefined rhel}
BuildRequires: python3-devel
BuildRequires: pyproject-rpm-macros >= 0-51
%if %{with tests}
# we avoid using %%pyproject_buildrequires -x testing as it mixes optional and non-optional deps
BuildRequires: python3-attrs >= 19.2
BuildRequires: python3-hypothesis >= 3.56
BuildRequires: python3-pygments >= 2.7.2
BuildRequires: python3-xmlschema
%if %{with optional_tests}
BuildRequires: python3-argcomplete
#BuildRequires: python3-asynctest -- not packaged in Fedora
BuildRequires: python3-decorator
BuildRequires: python3-jinja2
BuildRequires: python3-mock
BuildRequires: python3-nose
BuildRequires: python3-numpy
BuildRequires: python3-pexpect
BuildRequires: python3-pytest-xdist
BuildRequires: python3-twisted
BuildRequires: /usr/bin/lsof
%endif
%if %{with timeout}
BuildRequires: python3-pytest-timeout
%endif
%endif
%if %{with docs}
BuildRequires: %{_bindir}/rst2html
# pluggy >= 1 is needed to build the docs, older versions are allowed on runtime:
BuildRequires: python3-pluggy >= 1
BuildRequires: python3-pygments-pytest
BuildRequires: python3-Pallets-Sphinx-Themes
BuildRequires: python3-sphinx
BuildRequires: python3-sphinx-removed-in
BuildRequires: python3-sphinxcontrib-trio
# See doc/en/conf.py -- sphinxcontrib.inkscapeconverter is only used when inkscape is available
# we don't BR inkscape so we generally don't need it, but in case inkscape is installed accidentally:
BuildRequires: (python3-sphinxcontrib-inkscapeconverter if inkscape)
BuildRequires: make
%endif
BuildArch: noarch
%description
The pytest framework makes it easy to write small tests, yet scales to support
complex functional testing for applications and libraries.
%package -n python3-%{name}
Summary: Simple powerful testing with Python
Provides: pytest = %{version}-%{release}
%description -n python3-%{name}
The pytest framework makes it easy to write small tests, yet scales to support
complex functional testing for applications and libraries.
%prep
%autosetup -p1 -n %{name}-%{base_version}%{?prerelease}
# Between 7.2.0 and 7.2.1 the tests were updated for pygments 2.14.
# See https://github.com/pytest-dev/pytest/pull/10632 + 10637 (backport to 7.2).
# To make the tests work with pygments 2.13, we set the added {endline}s to empty.
# Once pygments 2.14+ is omnipresent, feel free to remove this hack,
# but bump the minimal BuildRequired version of python3-pygments to 2.14.
%if v"0%(%{python3} -c "import pygments; print(pygments.__version__)" 2>/dev/null)" < v"2.14~~"
sed -i 's/"endline": "\\x1b\[90m\\x1b\[39;49;00m",/"endline": "",/' testing/conftest.py
%endif
%generate_buildrequires
%pyproject_buildrequires -r
%build
%pyproject_wheel
%if %{with docs}
for l in doc/* ; do
%make_build -C $l html PYTHONPATH="$(pwd)/src"
done
for f in README CHANGELOG CONTRIBUTING ; do
rst2html ${f}.rst > ${f}.html
done
%endif
%install
%pyproject_install
%pyproject_save_files _pytest pytest py
mv %{buildroot}%{_bindir}/pytest %{buildroot}%{_bindir}/pytest-%{python3_version}
ln -snf pytest-%{python3_version} %{buildroot}%{_bindir}/pytest-3
mv %{buildroot}%{_bindir}/py.test %{buildroot}%{_bindir}/py.test-%{python3_version}
ln -snf py.test-%{python3_version} %{buildroot}%{_bindir}/py.test-3
# We use 3.X per default
ln -snf pytest-%{python3_version} %{buildroot}%{_bindir}/pytest
ln -snf py.test-%{python3_version} %{buildroot}%{_bindir}/py.test
%if %{with docs}
mkdir -p _htmldocs/html
for l in doc/* ; do
# remove hidden file
rm ${l}/_build/html/.buildinfo
mv ${l}/_build/html _htmldocs/html/${l##doc/}
done
%endif
# remove shebangs from all scripts
find %{buildroot}%{python3_sitelib} \
-name '*.py' \
-exec sed -i -e '1{/^#!/d}' {} \;
%check
%if %{with tests}
%global __pytest %{buildroot}%{_bindir}/pytest
# optional_tests deps contain pytest-xdist, so we can use it to run tests faster
%pytest testing %{?with_timeout:--timeout=30} %{?with_optional_tests:-n auto} -rs
%else
%pyproject_check_import
%endif
%files -n python3-%{name} -f %{pyproject_files}
%if %{with docs}
%doc CHANGELOG.html
%doc README.html
%doc CONTRIBUTING.html
%doc _htmldocs/html
%endif
%{_bindir}/pytest
%{_bindir}/pytest-3
%{_bindir}/pytest-%{python3_version}
%{_bindir}/py.test
%{_bindir}/py.test-3
%{_bindir}/py.test-%{python3_version}
%changelog
%autochangelog