2025-10-30 11:13:38 +01:00

280 lines
7.6 KiB
INI

# It would be nice to merge this into pyproject.toml, unfortunately as of 4.23.2 they don't support generative environments when using TOML
[tox]
skipsdist = True
skip_missing_interpreters = True
envlist =
ansible{2.15}-py{39,310,311}-{with_constraints,without_constraints}
ansible{2.16,2.17}-py{310,311,312}-{with_constraints,without_constraints}
ansible{2.18}-py{311,312,313}-{with_constraints,without_constraints}
[common]
collection_name = amazon.aws
collection_path = amazon/aws
format_dirs = {toxinidir}/plugins {toxinidir}/tests
lint_dirs = {toxinidir}/plugins {toxinidir}/tests
ansible_desc =
ansible2.15: Ansible-core 2.15
ansible2.16: Ansible-core 2.16
ansible2.17: Ansible-core 2.17
ansible2.18: Ansible-core 2.18
const_desc =
with_constraints: (With boto3/botocore constraints)
ansible_home = {envtmpdir}/ansible_home
ansible_collections_path = {[common]ansible_home}/collections
full_collection_path = {[common]ansible_home}/collections/ansible_collections/{[common]collection_path}
[testenv]
description = Run the unit tests {[common]ansible_desc}/{base_python} {[common]const_desc}
set_env =
ANSIBLE_HOME={[common]ansible_home}
ANSIBLE_COLLECTIONS_PATH={[common]ansible_collections_path}
# ansible_pytest_collections is more aggressive than pytest_ansible when injecting collections into the import path
# not needed if unit tests are under tests/unit/plugins rather than directly under tests/unit
# ANSIBLE_CONTROLLER_MIN_PYTHON_VERSION=3.11
# PYTEST_PLUGINS=ansible_test._util.target.pytest.plugins.ansible_pytest_collections
labels = unit
deps =
pytest
mock
pytest-mock
pytest-cov
pytest-ansible
pytest-xdist
-rtest-requirements.txt
-rtests/unit/requirements.txt
ansible2.15: ansible-core>2.15,<2.16
ansible2.16: ansible-core>2.16,<2.17
ansible2.17: ansible-core>2.17,<2.18
ansible2.18: ansible-core>2.18,<2.19
with_constraints: -rtests/unit/constraints.txt
allowlist_externals = rsync
change_dir = {[common]full_collection_path}
commands_pre =
rsync --delete --exclude=.tox -qraugpo {toxinidir}/ {[common]full_collection_path}/
ansible-galaxy collection install git+https://github.com/ansible-collections/community.aws.git
commands =
pytest \
--cov-report html \
--cov plugins/callback \
--cov plugins/inventory \
--cov plugins/lookup \
--cov plugins/module_utils \
--cov plugins/modules \
--cov plugins/plugin_utils \
--cov plugins \
--ansible-host-pattern localhost \
{posargs:tests/unit/}
[testenv:clean]
description = Remove test results and caches
allowlist_externals = rm
deps = coverage
skip_install = true
change_dir = {toxinidir}
commands_pre =
commands =
coverage erase
rm -rf tests/output/ htmlcov/ .mypy_cache/ complexity/ .ruff_cache/
[testenv:complexity-report]
labels = future-lint
description = Generate a HTML complexity report in the complexity directory
deps =
flake8-pyproject
flake8-html
change_dir = {toxinidir}
commands_pre =
commands =
-flake8 \
--select C90 \
--max-complexity 10 \
--format=html \
--htmldir={posargs:complexity} \
{posargs:{[common]lint_dirs}}
[testenv:ansible-lint]
labels = lint
description = Run ansible-lint
deps =
ansible-lint >= 25.1.2
jmespath
change_dir = {toxinidir}
commands_pre =
commands =
ansible-lint \
--skip-list=name[missing],yaml[line-length],args[module],run-once[task],ignore-errors,sanity[cannot-ignore],run-once[play] \
{posargs:{[common]lint_dirs}}
[testenv:black]
labels = format
description = Apply "black" formatting
depends =
flynt, isort
deps =
black >=23.0, <24.0
change_dir = {toxinidir}
commands_pre =
commands =
black {posargs:{[common]format_dirs}}
[testenv:black-lint]
labels = lint
description = Lint against "black" formatting standards
deps =
{[testenv:black]deps}
change_dir = {toxinidir}
commands_pre =
commands =
black --check --diff {posargs:{[common]format_dirs}}
[testenv:isort]
labels = format
description = Sort imports
deps =
isort
change_dir = {toxinidir}
commands_pre =
commands =
isort {posargs:{[common]format_dirs}}
[testenv:isort-lint]
labels = lint
description = Lint for import sorting
deps =
{[testenv:isort]deps}
change_dir = {toxinidir}
commands_pre =
commands =
isort --check-only --diff {posargs:{[common]format_dirs}}
[testenv:flynt]
labels = format
description = Apply flint (f-string) formatting
deps =
flynt
change_dir = {toxinidir}
commands_pre =
commands =
flynt {posargs:{[common]format_dirs}}
[testenv:flynt-lint]
labels = lint
description = Run flint (f-string) linting
deps =
flynt
change_dir = {toxinidir}
commands_pre =
commands =
flynt --dry-run --fail-on-change {posargs:{[common]format_dirs}}
[testenv:flake8-lint]
labels = lint
description = Run FLAKE8 linting
deps =
flake8
flake8-pyproject
change_dir = {toxinidir}
commands_pre =
commands =
flake8 {posargs:{[common]format_dirs}}
[testenv:pylint-lint]
labels = lint
description = Run pylint tests that are disabled by the default Ansible sanity tests
deps =
pylint
change_dir = {toxinidir}
commands_pre =
commands =
pylint \
--disable R,C,W,E \
--enable pointless-statement \
--enable consider-using-dict-items \
--enable assignment-from-no-return \
--enable no-else-continue \
--enable no-else-break \
--enable simplifiable-if-statement \
--enable pointless-string-statement \
--enable redefined-outer-name \
--enable redefined-builtin \
--enable unused-import \
{posargs:{[common]lint_dirs}}
[testenv:ruff]
description = lint source code
labels = format-future
deps =
ruff
change_dir = {toxinidir}
commands_pre =
commands =
ruff check --fix {posargs:{[common]lint_dirs}}
ruff format {posargs:{[common]lint_dirs}}
[testenv:ruff-lint]
description = lint source code
labels = lint-future
deps =
ruff
change_dir = {toxinidir}
commands_pre =
commands =
ruff check --diff --unsafe-fixes {posargs:{[common]lint_dirs}}
ruff check {posargs:{[common]lint_dirs}}
[testenv:ansible-lint-future]
labels = future-lint
description = Run ansible-lint
deps =
ansible-lint
jmespath
git+https://github.com/ansible/ansible.git@devel
shellcheck-py
commands =
ansible-lint \
{posargs:{[common]lint_dirs}}
[testenv:ansible-sanity]
labels = future-lint
description = Run latest (devel) Ansible sanity tests
deps =
git+https://github.com/ansible/ansible.git@devel
shellcheck-py
commands =
ansible-test sanity
[testenv:mypy-lint]
allowlist_externals = rsync,ln
labels = future-lint
description = Run mypi type tests
set_env =
ANSIBLE_HOME={[common]ansible_home}
ANSIBLE_COLLECTIONS_PATH={[common]ansible_collections_path}
MYPYPATH={[common]ansible_home}
deps =
mypy
# ansible-core
git+https://github.com/ansible/ansible.git@devel
botocore
boto3
placebo
typing_extensions
commands_pre =
rsync --delete --exclude=.tox -qraugpo {toxinidir}/ {[common]full_collection_path}/
ansible-galaxy collection install git+https://github.com/ansible-collections/community.aws.git
ln -s {env_site_packages_dir}/ansible {[common]ansible_collections_path}/ansible
ln -s {[common]ansible_home}/collections/ansible_collections {[common]ansible_home}/ansible_collections
commands =
# TODO: passing directories doesn't work well, it's better to pass the package
# we might want to consider manipulating posargs/directories into the package names
mypy \
--check-untyped-defs \
--namespace-packages --explicit-package-bases \
--follow-imports silent \
-p ansible_collections.amazon.aws.plugins.plugin_utils \
-p ansible_collections.amazon.aws.plugins.module_utils