diff --git a/doc/source/dev/devsetup.rst b/doc/source/dev/devsetup.rst index 6c8eef4b..67398a7f 100644 --- a/doc/source/dev/devsetup.rst +++ b/doc/source/dev/devsetup.rst @@ -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 `_ for more information how tests can be run. diff --git a/tox.ini b/tox.ini new file mode 100644 index 00000000..b14ff695 --- /dev/null +++ b/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