tests: use tox and overhaul project testing

To properly test the project commands, it would be best to have a
fresh west bootstrapper package created and installed on PATH, so it
could be used to run commands exactly as they'd happen if we package
and ship the working tree.

To make that easier, add a dependency on tox and use it for testing:

https://tox.readthedocs.io/en/latest/

From now on, we'll test west by running 'tox' from the repository
root.  This has several advantages over running pytest directly:

- "Just run tox": there are no longer any differences in test invocation
  between POSIX OSes and Windows.

- tox creates an sdist package of the current tree using our setup.py
  and installs it into a new virtual environment, then runs tests
  there.  This removes interference from other packages installed on
  the host (like released bootstrappers that are also installed)

- we get to run multiple shell commands in order, should that ever be needed,
  in our test procedures in a way that won't affect users

With that done, we can re-work the multirepo command testing to invoke
the bootstrapper in the virtual environment, adding various tests and
filling in longstanding testing gaps by adding increased checking of
the results (currently, much of the testing just checks whether
commands do or do not error out, which isn't enough).

These changes were made with a view towards the upcoming changes which
are planned before releasing west "into the wild": the test case code
should be mostly the same before and after the changes, so this serves
as a good baseline against regressions introduced by those upcoming
changes.

Signed-off-by: Marti Bolivar <marti@foundries.io>

[wip] debugging shippable results

Signed-off-by: Marti Bolivar <marti@foundries.io>

[wip] just test one py3

shutil.which west is picking up a 3.4 version in the 3.6 test, oddly

Signed-off-by: Marti Bolivar <marti@foundries.io>
This commit is contained in:
Marti Bolivar 2019-01-04 14:41:24 -07:00
parent f9c8e81073
commit 18060dd02a
6 changed files with 706 additions and 328 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ __pycache__/
.pytest_cache/
.eggs/
shippable/
.tox/

View File

@ -9,9 +9,6 @@ python:
build:
ci:
- python setup.py bdist_wheel
- pip install dist/west*.whl
- pip install -r tests_requirements.txt
- pip install tox
- mkdir -p shippable/{testresults,codecoverage}
- PYTHONPATH=src pytest --junitxml=shippable/testresults/nosetests.xml tests
- PYTHONPATH=src pytest --cov=west --cov-report=xml:shippable/codecoverage/coverage.xml tests
- tox -- --junitxml=$PWD/shippable/testresults/nosetests.xml --cov=west --cov-report=xml:$PWD/shippable/codecoverage/coverage.xml tests

View File

@ -16,7 +16,7 @@ a directory of your choosing::
mkdir zephyrproject && cd zephyrproject
west init
west fetch
west clone
What just happened:
@ -27,9 +27,9 @@ What just happened:
one supported by the bootstrapper itself; all other commands are
implemented in the west source repository it clones.
- ``west fetch`` clones the repositories in the manifest, creating
- ``west clone`` clones the repositories in the manifest, creating
working trees in the installation directory. In this case, the
bootstrapper notices the command (``fetch``) is not ``init``, and
bootstrapper notices the command (``clone``) is not ``init``, and
delegates handling to the "main" west implementation in the source
repository it cloned in the previous step.
@ -63,17 +63,19 @@ command with ``west <command> -h``. For example::
Test Suite
----------
To run the test suite, run this from the west repository::
Before running tests, install tox::
pip3 install -r tests_requirements.txt
# macOS, Windows
pip3 install tox
Then, in a Bash shell::
# Linux
pip3 install --user tox
PYTHONPATH=src py.test
Then, to run the test suite locally::
On Windows::
tox
cmd /C "set PYTHONPATH=/path/to/west/src && py.test"
See the tox configuration file, tox.ini, for more details.
Hacking on West
---------------

File diff suppressed because it is too large Load Diff

16
tox.ini Normal file
View File

@ -0,0 +1,16 @@
[tox]
envlist=py3-{posix,windows}
skip_missing_interpreters=true
[testenv]
deps = -rtox_deps.txt
platform = posix: (linux|macos)
windows: win32
whitelist_externals =
py.test
# Tests which import west modules directly from src need this PYTHONPATH
# available. The sdist which tox builds and installs only contains the
# bootstrapper modules.
setenv = PYTHONPATH={toxinidir}/src
commands =
py.test {posargs:tests}