forked from canonical/operator-libs-linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tox.ini
95 lines (88 loc) · 2.59 KB
/
tox.ini
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# Copyright 2021 Canonical Ltd.
# See LICENSE file for licensing details.
[tox]
skipsdist=True
skip_missing_interpreters = True
envlist = lint, unit
[vars]
src_dir = {toxinidir}/src/
tst_dir = {toxinidir}/tests/
itst_dir = {toxinidir}/tests/integration
lib_dir = {toxinidir}/lib/charms/operator_libs_linux/
all_dir = {[vars]src_dir} {[vars]tst_dir} {[vars]lib_dir}
lxd_name = ops-libs-test
[testenv]
setenv =
PYTHONPATH = {toxinidir}:{toxinidir}/lib:{[vars]src_dir}
PYTHONBREAKPOINT=ipdb.set_trace
PY_COLORS=1
passenv =
PYTHONPATH
HOME
PATH
CHARM_BUILD_DIR
MODEL_SETTINGS
HTTP_PROXY
HTTPS_PROXY
NO_PROXY
[testenv:fmt]
description = Apply coding style standards to code
deps =
black
isort
commands =
isort {[vars]all_dir}
black {[vars]all_dir}
[testenv:lint]
description = Check code against coding style standards
deps =
black
flake8
flake8-docstrings
flake8-copyright
flake8-builtins
mypy
pyproject-flake8
pep8-naming
isort
commands =
# pflake8 wrapper suppports config from pyproject.toml
pflake8 {[vars]all_dir}
isort --check-only --diff {[vars]all_dir}
black --check --diff {[vars]all_dir}
[testenv:unit]
description = Run unit tests
deps =
pytest
coverage[toml]
-r{toxinidir}/requirements.txt
pyfakefs==4.4.0
commands =
coverage run --source={[vars]lib_dir} \
-m pytest --ignore={[vars]tst_dir}integration -v --tb native {posargs}
coverage report
[testenv:integration]
description = Build a LXD container for integration tests then run the tests
allowlist_externals =
lxc
bash
commands =
# Create a LXC container with the relevant packages installed
bash -c 'lxc launch -qe ubuntu:focal {[vars]lxd_name} -c=user.user-data="$(<{[vars]itst_dir}/test_setup.yaml)"'
# Wait for the cloud-init process to finish
lxc exec {[vars]lxd_name} -- bash -c "cloud-init status -w >/dev/null 2>&1"
# Copy all the files needed for integration testing
lxc file push -qp {toxinidir}/tox.ini {[vars]lxd_name}/{[vars]lxd_name}/
lxc file push -qp {toxinidir}/pyproject.toml {[vars]lxd_name}/{[vars]lxd_name}/
lxc file push -qpr {toxinidir}/lib {[vars]lxd_name}/{[vars]lxd_name}/
lxc file push -qpr {[vars]tst_dir} {[vars]lxd_name}/{[vars]lxd_name}/
# Run the tests
lxc exec {[vars]lxd_name} -- tox -c /{[vars]lxd_name}/tox.ini -e integration-tests {posargs}
commands_post =
-lxc stop {[vars]lxd_name}
[testenv:integration-tests]
description = Run integration tests
deps =
pytest
commands =
pytest -v --tb native --ignore={[vars]tst_dir}unit --log-cli-level=INFO -s {posargs}