Skip to content

Commit

Permalink
cloudinit: move to pytest for running tests
Browse files Browse the repository at this point in the history
As the nose docs[0] themselves note, it has been in maintenance mode for
the past several years.  pytest is an actively developed, featureful and
popular alternative that the nose docs themselves recommend.

[0] https://nose.readthedocs.io/en/latest/
  • Loading branch information
Daniel Watkins authored and OddBloke committed Feb 14, 2020
1 parent c90932f commit ad07235
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 30 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Expand Up @@ -16,13 +16,13 @@ matrix:
- python: 3.6
env:
TOXENV=py3
NOSE_VERBOSE=2 # List all tests run by nose
PYTEST_ADDOPTS=-v # List all tests run by pytest
- install:
- git fetch --unshallow
- sudo apt-get build-dep -y cloud-init
- sudo apt-get install -y --install-recommends sbuild ubuntu-dev-tools fakeroot tox
# These are build deps but not pulled in by the build-dep call above
- sudo apt-get install -y --install-recommends dh-systemd python3-coverage python3-contextlib2
- sudo apt-get install -y --install-recommends dh-systemd python3-coverage python3-contextlib2 python3-pytest python3-pytest-cov
- pip install .
- pip install tox
# bionic has lxd from deb installed, remove it first to ensure
Expand All @@ -46,7 +46,7 @@ matrix:
- python: 3.5
env:
TOXENV=xenial
NOSE_VERBOSE=2 # List all tests run by nose
PYTEST_ADDOPTS=-v # List all tests run by pytest
# Travis doesn't support Python 3.4 on bionic, so use xenial
dist: xenial
- python: 3.6
Expand Down
6 changes: 2 additions & 4 deletions Makefile
Expand Up @@ -2,8 +2,6 @@ CWD=$(shell pwd)
PYVER ?= $(shell for p in python3 python2; do \
out=$$(command -v $$p 2>&1) && echo $$p && exit; done; exit 1)

noseopts ?= -v

YAML_FILES=$(shell find cloudinit tests tools -name "*.yaml" -type f )
YAML_FILES+=$(shell find doc/examples -name "cloud-config*.txt" -type f )

Expand Down Expand Up @@ -48,10 +46,10 @@ pyflakes3:
@$(CWD)/tools/run-pyflakes3

unittest: clean_pyc
nosetests $(noseopts) tests/unittests cloudinit
python -m pytest -v tests/unittests cloudinit

unittest3: clean_pyc
nosetests3 $(noseopts) tests/unittests cloudinit
python3 -m pytest -v tests/unittests cloudinit

ci-deps-ubuntu:
@$(PYVER) $(CWD)/tools/read-dependencies --distro ubuntu --test-distro
Expand Down
3 changes: 3 additions & 0 deletions packages/pkg-deps.json
Expand Up @@ -45,6 +45,9 @@
"pyserial" : {
"2" : "pyserial"
},
"pytest": {
"3": "python36-pytest"
},
"requests" : {
"3" : "python36-requests"
},
Expand Down
7 changes: 2 additions & 5 deletions test-requirements.txt
@@ -1,11 +1,8 @@
# Needed generally in tests
httpretty>=0.7.1
nose
pytest
unittest2
coverage

# Only needed if you want to know the test times
# nose-timer
pytest-cov

# Only really needed on older versions of python
contextlib2
Expand Down
12 changes: 6 additions & 6 deletions tools/run-container
Expand Up @@ -287,8 +287,8 @@ prep() {
install_packages "$@"
}

nose() {
python3 -m nose "$@"
pytest() {
python3 -m pytest "$@"
}

is_done_cloudinit() {
Expand Down Expand Up @@ -478,10 +478,10 @@ main() {

if [ -n "$unittest" ]; then
debug 1 "running unit tests."
run_self_inside_as_cd "$name" "$user" "$cdir" nose \
run_self_inside_as_cd "$name" "$user" "$cdir" pytest \
tests/unittests cloudinit/ || {
errorrc "nosetests failed.";
errors[${#errors[@]}]="nosetests"
errorrc "pytest failed.";
errors[${#errors[@]}]="pytest"
}
fi

Expand Down Expand Up @@ -557,7 +557,7 @@ main() {
}

case "${1:-}" in
prep|os_info|wait_inside|nose) _n=$1; shift; "$_n" "$@";;
prep|os_info|wait_inside|pytest) _n=$1; shift; "$_n" "$@";;
*) main "$@";;
esac

Expand Down
2 changes: 1 addition & 1 deletion tools/tox-venv
Expand Up @@ -116,7 +116,7 @@ Usage: ${0##*/} [--no-create] tox-environment [command [args]]
be read from tox.ini. This allows you to do:
tox-venv py27 - tests/some/sub/dir
and have the 'command' read correctly and have that execute:
python -m nose tests/some/sub/dir
python -m pytest tests/some/sub/dir
EOF

if [ -f "$tox_ini" ]; then
Expand Down
21 changes: 10 additions & 11 deletions tox.ini
Expand Up @@ -3,11 +3,11 @@ envlist = py3, xenial, pycodestyle, pyflakes, pylint
recreate = True

[testenv]
commands = python -m nose {posargs:tests/unittests cloudinit}
commands = {envpython} -m pytest {posargs:tests/unittests cloudinit}
setenv =
LC_ALL = en_US.utf-8
passenv=
NOSE_VERBOSE
PYTEST_ADDOPTS

[testenv:pycodestyle]
basepython = python3
Expand All @@ -32,11 +32,10 @@ commands = {envpython} -m pylint {posargs:cloudinit tests tools}
[testenv:py3]
basepython = python3
deps =
nose-timer
-r{toxinidir}/test-requirements.txt
commands = {envpython} -m nose --with-timer --timer-top-n 10 \
{posargs:--with-coverage --cover-erase --cover-branches \
--cover-inclusive --cover-package=cloudinit \
commands = {envpython} -m pytest \
--durations 10 \
{posargs:--cov=cloudinit --cov-branch \
tests/unittests cloudinit}

[testenv:py27]
Expand All @@ -45,7 +44,7 @@ deps = -r{toxinidir}/test-requirements.txt

[testenv:py26]
deps = -r{toxinidir}/test-requirements.txt
commands = nosetests {posargs:tests/unittests cloudinit}
commands = {envpython} -m pytest {posargs:tests/unittests cloudinit}
setenv =
LC_ALL = C

Expand All @@ -65,7 +64,7 @@ commands =
[testenv:xenial]
commands =
python ./tools/pipremove jsonschema
python -m nose {posargs:tests/unittests cloudinit}
py.test {posargs:tests/unittests cloudinit}
basepython = python3
deps =
# requirements
Expand All @@ -83,13 +82,13 @@ deps =
# test-requirements
httpretty==0.9.6
mock==1.3.0
nose==1.3.7
pytest==2.8.7
unittest2==1.1.0
contextlib2==0.5.1

[testenv:centos6]
basepython = python2.6
commands = nosetests {posargs:tests/unittests cloudinit}
commands = {envpython} -m pytest {posargs:tests/unittests cloudinit}
deps =
# requirements
argparse==1.2.1
Expand All @@ -104,7 +103,7 @@ deps =

[testenv:opensusel150]
basepython = python2.7
commands = nosetests {posargs:tests/unittests cloudinit}
commands = {envpython} -m pytest {posargs:tests/unittests cloudinit}
deps =
# requirements
jinja2==2.10
Expand Down

0 comments on commit ad07235

Please sign in to comment.