Add %tox macro to invoke tests
This commit is contained in:
parent
0124d2a76f
commit
ec073171f3
60
README.md
60
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,
|
For projects that specify test requirements in their [tox] configuration,
|
||||||
these can be added using the `-t` flag followed by the tox environment.
|
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`,
|
For example, if upstream suggests running the tests on Python 3.7 with `tox -e py37`,
|
||||||
the test deps would be generated by:
|
the test deps would be generated by:
|
||||||
|
|
||||||
%generate_buildrequires
|
%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
|
Note that `-t` implies `-r`, because tox normally assumes the package is installed
|
||||||
including all the runtime dependencies.
|
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]: https://tox.readthedocs.io/
|
||||||
[tox-current-env]: https://github.com/fedora-python/tox-current-env/
|
[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
|
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 `-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 517]: https://www.python.org/dev/peps/pep-0517/
|
||||||
[PEP 518]: https://www.python.org/dev/peps/pep-0518/
|
[PEP 518]: https://www.python.org/dev/peps/pep-0518/
|
||||||
|
@ -17,7 +17,8 @@ if [ -d %{buildroot}%{python3_sitearch} ]; then
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
%toxenv py%{python3_version_nodots}
|
%default_toxenv py%{python3_version_nodots}
|
||||||
|
%toxenv %{default_toxenv}
|
||||||
|
|
||||||
%pyproject_buildrequires(rx:t:) %{expand:\\\
|
%pyproject_buildrequires(rx:t:) %{expand:\\\
|
||||||
%{-t:%{expand:%global toxenv %{-t*}}}
|
%{-t:%{expand:%global toxenv %{-t*}}}
|
||||||
@ -31,3 +32,10 @@ if [ -f %{__python3} ]; then
|
|||||||
%{__python3} -I %{_rpmconfigdir}/redhat/pyproject_buildrequires.py %{?**}
|
%{__python3} -I %{_rpmconfigdir}/redhat/pyproject_buildrequires.py %{?**}
|
||||||
fi
|
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}}" %{?*}
|
||||||
|
}
|
||||||
|
@ -78,6 +78,7 @@ install -m 644 pyproject_buildrequires.py %{buildroot}%{_rpmconfigdir}/redhat/
|
|||||||
%changelog
|
%changelog
|
||||||
* Fri Jul 26 2019 Miro Hrončok <mhroncok@redhat.com> - 0-5
|
* Fri Jul 26 2019 Miro Hrončok <mhroncok@redhat.com> - 0-5
|
||||||
- Allow to fetch test dependencies from tox
|
- 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
|
* Fri Jul 26 2019 Fedora Release Engineering <releng@fedoraproject.org> - 0-4
|
||||||
- Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild
|
- Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild
|
||||||
|
@ -40,8 +40,7 @@ Summary: %{summary}
|
|||||||
|
|
||||||
|
|
||||||
%check
|
%check
|
||||||
export PYTHONPATH=%{buildroot}%{python3_sitelib}
|
%tox
|
||||||
%{__python3} -m pytest
|
|
||||||
|
|
||||||
|
|
||||||
%files -n python3-%{pypi_name}
|
%files -n python3-%{pypi_name}
|
||||||
|
Loading…
Reference in New Issue
Block a user