Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cloudinit: move to pytest for running tests #211

Merged
merged 3 commits into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we are dropping Python 2 support with 20.1 release, I think the unittest target should be dropped rather than changing it.


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"
smoser marked this conversation as resolved.
Show resolved Hide resolved
},
"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
73 changes: 29 additions & 44 deletions tox.ini
@@ -1,13 +1,13 @@
[tox]
envlist = py3, xenial, pycodestyle, pyflakes, pylint
envlist = py3, xenial-dev, 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,23 +32,16 @@ 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]
basepython = python2.7
deps = -r{toxinidir}/test-requirements.txt

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

[flake8]
#H102 Apache 2.0 license header not found
ignore=H404,H405,H105,H301,H104,H403,H101,H102,H106,H304
Expand All @@ -62,11 +55,15 @@ commands =
{envpython} -m sphinx {posargs:doc/rtd doc/rtd_html}
doc8 doc/rtd

[testenv:xenial]
commands =
python ./tools/pipremove jsonschema
python -m nose {posargs:tests/unittests cloudinit}
basepython = python3
[xenial-shared-deps]
# The version of pytest in xenial doesn't work with Python 3.8, so we define
# two xenial environments: [testenv:xenial] runs the tests with exactly the
# version of pytest present in xenial, and is used in CI. [testenv:xenial-dev]
# runs the tests with the lowest version of pytest that works with Python 3.8,
# 3.0.7, but keeps the other dependencies at xenial's level.
#
# (This section is not a testenv, it is used to maintain a single definition of
# the dependencies shared between the two xenial testenvs.)
deps =
# requirements
jinja2==2.8
Expand All @@ -83,38 +80,26 @@ deps =
# test-requirements
httpretty==0.9.6
mock==1.3.0
nose==1.3.7
unittest2==1.1.0
contextlib2==0.5.1

[testenv:centos6]
basepython = python2.6
commands = nosetests {posargs:tests/unittests cloudinit}
[testenv:xenial]
commands =
python ./tools/pipremove jsonschema
python -m pytest {posargs:tests/unittests cloudinit}
basepython = python3
deps =
# requirements
argparse==1.2.1
jinja2==2.2.1
pyyaml==3.10
oauthlib==0.6.0
configobj==4.6.0
requests==2.6.0
jsonpatch==1.2
six==1.9.0
-r{toxinidir}/test-requirements.txt
# Refer to the comment in [xenial-shared-deps] for details
{[xenial-shared-deps]deps}
smoser marked this conversation as resolved.
Show resolved Hide resolved
pytest==2.8.7

[testenv:opensusel150]
basepython = python2.7
commands = nosetests {posargs:tests/unittests cloudinit}
[testenv:xenial-dev]
commands = {[testenv:xenial]commands}
basepython = {[testenv:xenial]basepython}
deps =
# requirements
jinja2==2.10
PyYAML==3.12
oauthlib==2.0.6
configobj==5.0.6
requests==2.18.4
jsonpatch==1.16
six==1.11.0
-r{toxinidir}/test-requirements.txt
# Refer to the comment in [xenial-shared-deps] for details
{[xenial-shared-deps]deps}
pytest==3.0.7

[testenv:tip-pycodestyle]
commands = {envpython} -m pycodestyle {posargs:cloudinit/ tests/ tools/}
Expand Down