Add %tox macro to invoke tests

This commit is contained in:
Miro Hrončok 2019-07-26 17:50:36 +02:00
parent 0124d2a76f
commit ec073171f3
4 changed files with 69 additions and 5 deletions

View File

@ -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/

View File

@ -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}}" %{?*}
}

View File

@ -78,6 +78,7 @@ install -m 644 pyproject_buildrequires.py %{buildroot}%{_rpmconfigdir}/redhat/
%changelog
* Fri Jul 26 2019 Miro Hrončok <mhroncok@redhat.com> - 0-5
- Allow to fetch test dependencies from tox
- Add %%tox macro to invoke tests
* Fri Jul 26 2019 Fedora Release Engineering <releng@fedoraproject.org> - 0-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild

View File

@ -40,8 +40,7 @@ Summary: %{summary}
%check
export PYTHONPATH=%{buildroot}%{python3_sitelib}
%{__python3} -m pytest
%tox
%files -n python3-%{pypi_name}