Skip to content

Commit

Permalink
Add tox configuration
Browse files Browse the repository at this point in the history
Tox makes it much easier to run the FuseSoC tests in an isolated
environment without installing fusesoc first, or overwriting a
production version.

Simply run `tox` in the FuseSoC root source directory to run all tests.

Fixes #213
  • Loading branch information
imphil committed Nov 18, 2020
1 parent c92c850 commit 63353c4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
15 changes: 11 additions & 4 deletions doc/source/dev/devsetup.rst
Expand Up @@ -68,16 +68,23 @@ Running tests
-------------

The FuseSoC contains unit tests written using the pytest framework.
To run the tests in an isolated environment it is recommended to run pytest through tox, which first creates a package of the source code, installs it, and then runs the tests.
This ensures that packaging and environment errors are less likely to slip through.

.. code-block:: bash
cd fusesoc/source/directory
# run all tests
python3 -m pytest
# Run all tests in an isolated environment (recommended)
tox
# All arguments passed to tox after -- are passed to pytest directly.
# E.g. run a single test: use filename::method_name, e.g.
tox -- tests/test_capi2.py::test_capi2_get_tool --verbose
# run a single test: use filename::method_name, e.g.
python3 -m pytest tests/test_capi2.py::test_capi2_get_tool --verbose
# Alternatively, tests can be run directly from the source tree.
# E.g. to run a single test: use filename::method_name, e.g.
python3 -m pytest
Refer to the `pytest documentation <https://docs.pytest.org/en/latest/>`_ for more information how tests can be run.

Expand Down
25 changes: 25 additions & 0 deletions tox.ini
@@ -0,0 +1,25 @@
[tox]
envlist = py3

[testenv]
# Some tests need an initialized FuseSoC library to be present. To make tests
# reproducible tox doesn't use the library installed into the user's home
# directory, but creates an isolated home directory within the tox working
# directory, and clears it out after each test.
deps = pytest
commands =
/bin/rm -rf {toxworkdir}/.tmp/homedir
fusesoc init -y
fusesoc list-cores
fusesoc library update
pytest {posargs}

setenv =
MODEL_TECH = dummy_value
HOME = {toxworkdir}/.tmp/homedir
XDG_CACHE_HOME = {toxworkdir}/.tmp/homedir/.cache
XDG_DATA_HOME= {toxworkdir}/.tmp/homedir/.local/share
XDG_CONFIG_HOME = {toxworkdir}/.tmp/homedir/.config

whitelist_externals =
/bin/rm

0 comments on commit 63353c4

Please sign in to comment.