From ec073171f3e651a4e98df740602c8cc28e0e47b4 Mon Sep 17 00:00:00 2001 From: Miro Hrončok Date: Jul 29 2019 12:42:53 +0000 Subject: Add %tox macro to invoke tests --- diff --git a/README.md b/README.md index fe1ce03..7d5b7a9 100644 --- a/README.md +++ b/README.md @@ -57,11 +57,24 @@ For example, if upstream suggests installing test dependencies with For projects that specify test requirements in their [tox] configuration, these can be added using the `-t` flag followed by the tox environment. +The recommended tox environment (such as `py37` assuming the Fedora's Python version is 3.7) +is available in the `%{toxenv}` macro. For example, if upstream suggests running the tests on Python 3.7 with `tox -e py37`, the test deps would be generated by: %generate_buildrequires - %pyproject_buildrequires -t py37 + %pyproject_buildrequires -t %{toxenv} + +If upstream uses a custom derived environment, such as `py37-unit`, use: + + %pyproject_buildrequires -t %{toxenv}-unit + +Or specify more environments if needed: + + %pyproject_buildrequires -t %{toxenv}-unit,%{toxenv}-integration + +The `-t` option redefines `%{toxenv}` for further reuse. +Use `%{default_toxenv}` to get the default value. Note that `-t` implies `-r`, because tox normally assumes the package is installed including all the runtime dependencies. @@ -71,6 +84,49 @@ The `-t` option uses [tox-current-env]'s `--print-deps-only` behind the scenes. [tox]: https://tox.readthedocs.io/ [tox-current-env]: https://github.com/fedora-python/tox-current-env/ + +Running tox based tests +----------------------- + +In case you want to run the tests as specified in [tox] configuration, +you can use the `%tox` macro: + + %check + %tox + +The macro: + + - Always prepends `$PATH` with `%{buildroot}%{_bindir}` + - If not defined, sets `$PYTHONPATH` to `%{buildroot}%{python3_sitearch}:%{buildroot}%{python3_sitelib}` + - If not defined, sets `$TOX_TESTENV_PASSENV` to `*` + - Runs `tox` with `-q` (quiet), `--recreate` and `--current-env` (from [tox-current-env]) flags + - Implicitly uses the tox environment name stored in `%{toxenv}` - as overridden by `%pyproject_buildrequires -t` + +By using the `-e` flag, you can use a different tox environment(s): + + %check + %tox + %if %{with integration_test} + %tox -e % {default_toxenv}-integration + %endif + +If you wish to provide custom `tox` flags or arguments, add them after `--`: + + %tox -- --flag-for-tox + +If you wish to pass custom `posargs` to tox, use another `--`: + + %tox -- --flag-for-tox -- --flag-for-posargs + +Or (note the two sequential `--`s): + + %tox -- -- --flag-for-posargs + +**Warning:** This macro assumes you have used `%pyproject_buildrequires -t` in +`%generate_buildrequires`. If not, you need to add: + + BuildRequires: python3dist(tox-current-env) + Limitations ----------- @@ -85,7 +141,7 @@ Some valid Python version specifiers are not supported. The `-x` flag does not yet support multiple (comma-separated) extras. -The `-t` flag does not yet support a reasonable default. +The `-t` flag does not yet support being used without a value. [PEP 517]: https://www.python.org/dev/peps/pep-0517/ [PEP 518]: https://www.python.org/dev/peps/pep-0518/ diff --git a/macros.pyproject b/macros.pyproject index 817814d..0a4f37b 100644 --- a/macros.pyproject +++ b/macros.pyproject @@ -17,7 +17,8 @@ if [ -d %{buildroot}%{python3_sitearch} ]; then fi } -%toxenv py%{python3_version_nodots} +%default_toxenv py%{python3_version_nodots} +%toxenv %{default_toxenv} %pyproject_buildrequires(rx:t:) %{expand:\\\ %{-t:%{expand:%global toxenv %{-t*}}} @@ -31,3 +32,10 @@ if [ -f %{__python3} ]; then %{__python3} -I %{_rpmconfigdir}/redhat/pyproject_buildrequires.py %{?**} fi } + +%tox(e:) %{expand:\\\ +TOX_TESTENV_PASSENV="${TOX_TESTENV_PASSENV:-*}" \\ +PATH="%{buildroot}%{_bindir}:$PATH" \\ +PYTHONPATH="${PYTHONPATH:-%{buildroot}%{python3_sitearch}:%{buildroot}%{python3_sitelib}}" \\ +tox --current-env -q --recreate -e "%{-e:%{-e*}}%{!-e:%{toxenv}}" %{?*} +} diff --git a/pyproject-rpm-macros.spec b/pyproject-rpm-macros.spec index 393f640..1a31c0a 100644 --- a/pyproject-rpm-macros.spec +++ b/pyproject-rpm-macros.spec @@ -78,6 +78,7 @@ install -m 644 pyproject_buildrequires.py %{buildroot}%{_rpmconfigdir}/redhat/ %changelog * Fri Jul 26 2019 Miro Hrončok - 0-5 - Allow to fetch test dependencies from tox +- Add %%tox macro to invoke tests * Fri Jul 26 2019 Fedora Release Engineering - 0-4 - Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild diff --git a/tests/python-pluggy.spec b/tests/python-pluggy.spec index 74a772b..c77ff13 100644 --- a/tests/python-pluggy.spec +++ b/tests/python-pluggy.spec @@ -40,8 +40,7 @@ Summary: %{summary} %check -export PYTHONPATH=%{buildroot}%{python3_sitelib} -%{__python3} -m pytest +%tox %files -n python3-%{pypi_name}