1[tox]
2envlist = py3, xenial-dev, flake8, pylint
3recreate = True
4
5[testenv]
6commands = {envpython} -m pytest {posargs:tests/unittests cloudinit}
7setenv =
8    LC_ALL = en_US.utf-8
9passenv=
10    PYTEST_ADDOPTS
11
12[testenv:flake8]
13basepython = python3
14deps =
15    flake8==3.9.2
16commands = {envpython} -m flake8 {posargs:cloudinit/ tests/ tools/ setup.py}
17
18# https://github.com/gabrielfalcao/HTTPretty/issues/223
19setenv =
20    LC_ALL = en_US.utf-8
21
22[testenv:pylint]
23basepython = python3
24deps =
25    # requirements
26    pylint==2.11.1
27    # test-requirements because unit tests are now present in cloudinit tree
28    -r{toxinidir}/test-requirements.txt
29    -r{toxinidir}/integration-requirements.txt
30commands = {envpython} -m pylint {posargs:cloudinit tests tools}
31
32
33[testenv:py3]
34basepython = python3
35deps =
36    -r{toxinidir}/test-requirements.txt
37commands = {envpython} -m pytest \
38            --durations 10 \
39            {posargs:--cov=cloudinit --cov-branch \
40            tests/unittests cloudinit}
41
42[testenv:py27]
43basepython = python2.7
44deps = -r{toxinidir}/test-requirements.txt
45
46[flake8]
47# E226: missing whitespace around arithmetic operator
48# W503: line break before binary operator
49# W504: line break after binary operator
50ignore=E226,W503,W504
51exclude = .venv,.tox,dist,doc,*egg,.git,build,tools
52per-file-ignores =
53    cloudinit/cmd/main.py:E402
54
55[testenv:doc]
56basepython = python3
57deps =
58    -r{toxinidir}/doc-requirements.txt
59commands =
60    {envpython} -m sphinx {posargs:doc/rtd doc/rtd_html}
61    doc8 doc/rtd
62
63[xenial-shared-deps]
64# The version of pytest in xenial doesn't work with Python 3.8, so we define
65# two xenial environments: [testenv:xenial] runs the tests with exactly the
66# version of pytest present in xenial, and is used in CI.  [testenv:xenial-dev]
67# runs the tests with the lowest version of pytest that works with Python 3.8,
68# 3.0.7, but keeps the other dependencies at xenial's level.
69#
70# (This section is not a testenv, it is used to maintain a single definition of
71# the dependencies shared between the two xenial testenvs.)
72deps =
73    # requirements
74    jinja2==2.8
75    pyyaml==3.11
76    oauthlib==1.0.3
77    pyserial==3.0.1
78    configobj==5.0.6
79    requests==2.9.1
80    jsonschema
81    # test-requirements
82    pytest-catchlog==1.2.1
83
84[testenv:xenial]
85# When updating this commands definition, also update the definition in
86# [testenv:xenial-dev].  See the comment there for details.
87commands =
88  python ./tools/pipremove jsonschema
89  python -m pytest {posargs:tests/unittests cloudinit}
90basepython = python3
91deps =
92    # Refer to the comment in [xenial-shared-deps] for details
93    {[xenial-shared-deps]deps}
94    httpretty==0.8.6
95    jsonpatch==1.10
96    pytest==2.8.7
97
98[testenv:xenial-dev]
99# This should be:
100#   commands = {[testenv:xenial]commands}
101# but the version of pytest in xenial has a bug
102# (https://github.com/tox-dev/tox/issues/208) which means that the {posargs}
103# substitution variable is misparsed and causes a traceback.  Ensure that any
104# changes here are reflected in [testenv:xenial].
105commands =
106  python ./tools/pipremove jsonschema
107  python -m pytest {posargs:tests/unittests cloudinit}
108basepython = {[testenv:xenial]basepython}
109deps =
110    # Refer to the comment in [xenial-shared-deps] for details
111    {[xenial-shared-deps]deps}
112    # httpretty in xenial is 0.8.6, not 0.9.5.  The oldest version to work with
113    # Python 3.7+ is 0.9.5, because it is the first to include this commit:
114    # https://github.com/gabrielfalcao/HTTPretty/commit/5776d97da3992b9071db5e21faf175f6e8729060
115    httpretty==0.9.5
116    # jsonpatch in xenial is 1.10, not 1.19 (#839779). The oldest version
117    # to work with python3.6 is 1.16 as found in Artful.  To keep default
118    # invocation of 'tox' happy, accept the difference in version here.
119    jsonpatch==1.16
120    pytest==3.0.7
121
122[testenv:tip-flake8]
123commands = {envpython} -m flake8 {posargs:cloudinit/ tests/ tools/ setup.py}
124deps = flake8
125
126[testenv:tip-pylint]
127commands = {envpython} -m pylint {posargs:cloudinit tests tools}
128deps =
129    # requirements
130    pylint
131    # test-requirements
132    -r{toxinidir}/test-requirements.txt
133    -r{toxinidir}/integration-requirements.txt
134
135# Until Xenial tox support is dropped or bumps to tox:2.3.2, reflect changes to
136# deps into testenv:integration-tests-ci: commands, passenv and deps.
137# This is due to (https://github.com/tox-dev/tox/issues/208) which means that
138# the {posargs} handling and substitutions won't do what we want until tox 2.3.2
139# Once Xenial is dropped, integration-tests-ci can use proper substitution
140# commands = {[testenv:integration-tests]commands}
141[testenv:integration-tests]
142basepython = python3
143commands = {envpython} -m pytest --log-cli-level=INFO {posargs:tests/integration_tests}
144passenv = CLOUD_INIT_* SSH_AUTH_SOCK OS_*
145deps =
146    -r{toxinidir}/integration-requirements.txt
147
148[testenv:integration-tests-ci]
149commands = {envpython} -m pytest --log-cli-level=INFO {posargs:tests/integration_tests}
150passenv = CLOUD_INIT_* SSH_AUTH_SOCK OS_* TRAVIS
151deps =
152    -r{toxinidir}/integration-requirements.txt
153setenv =
154    PYTEST_ADDOPTS="-m ci and not adhoc"
155
156[testenv:integration-tests-jenkins]
157commands = {envpython} -m pytest --log-cli-level=INFO {posargs:tests/integration_tests}
158passenv = *_proxy CLOUD_INIT_* SSH_AUTH_SOCK OS_* GOOGLE_* GCP_*
159deps =
160    -r{toxinidir}/integration-requirements.txt
161setenv =
162    PYTEST_ADDOPTS="-m not adhoc"
163
164[pytest]
165# TODO: s/--strict/--strict-markers/ once xenial support is dropped
166testpaths = cloudinit tests/unittests
167addopts = --strict
168log_format = %(asctime)s %(levelname)-9s %(name)s:%(filename)s:%(lineno)d %(message)s
169log_date_format = %Y-%m-%d %H:%M:%S
170markers =
171    allow_subp_for: allow subp usage for the given commands (disable_subp_usage)
172    allow_all_subp: allow all subp usage (disable_subp_usage)
173    ci: run this integration test as part of CI test runs
174    ds_sys_cfg: a sys_cfg dict to be used by datasource fixtures
175    ec2: test will only run on EC2 platform
176    gce: test will only run on GCE platform
177    azure: test will only run on Azure platform
178    oci: test will only run on OCI platform
179    openstack: test will only run on openstack platform
180    lxd_config_dict: set the config_dict passed on LXD instance creation
181    lxd_container: test will only run in LXD container
182    lxd_setup: specify callable to be called between init and start
183    lxd_use_exec: `execute` will use `lxc exec` instead of SSH
184    lxd_vm: test will only run in LXD VM
185    not_xenial: test cannot run on the xenial release
186    not_bionic: test cannot run on the bionic release
187    no_container: test cannot run in a container
188    user_data: the user data to be passed to the test instance
189    instance_name: the name to be used for the test instance
190    sru_2020_11: test is part of the 2020/11 SRU verification
191    sru_2021_01: test is part of the 2021/01 SRU verification
192    sru_next: test is part of the next SRU verification
193    ubuntu: this test should run on Ubuntu
194    unstable: skip this test because it is flakey
195    adhoc: only run on adhoc basis, not in any CI environment (travis or jenkins)
196