Liam Young 0fe5f7dfb4 Add ops.scenario tests
Add ops.scenario tests. This allows each charm class to be easily
tested with different permutations of missing/incomplete/complete
relations.

This is a starting point for using ops.scenario, additional
tests should include: examining rendered files, peer relation,
test secrets events etc

Change-Id: I8ebdad250d7cb169c3c0d72858e0582000d98b6e
2023-09-19 06:35:29 +00:00

133 lines
3.0 KiB
INI

# Operator charm helper: tox.ini
[tox]
skipsdist = True
envlist = lint, py3
sitepackages = False
skip_missing_interpreters = False
minversion = 3.18.0
requires = virtualenv < 20.0
[vars]
src_path = {toxinidir}/ops_sunbeam
tst_path = {toxinidir}/tests/unit_tests/
scenario_tst_path = {toxinidir}/tests/scenario_tests/
tst_lib_path = {toxinidir}/tests/lib/
pyproject_toml = {toxinidir}/pyproject.toml
cookie_cutter_path = {toxinidir}/shared_code/sunbeam_charm/\{\{cookiecutter.service_name\}\}
all_path = {[vars]src_path} {[vars]tst_path}
[testenv]
basepython = python3
install_command =
pip install {opts} {packages}
commands =
stestr run --slowest {posargs}
pytest -v --tb native {[vars]scenario_tst_path} --log-cli-level=INFO
allowlist_externals =
git
charmcraft
fetch-libs.sh
deps =
-r{toxinidir}/test-requirements.txt
[testenv:fmt]
description = Apply coding style standards to code
deps =
black
isort
commands =
isort {[vars]all_path} --skip-glob {[vars]tst_lib_path} --skip {toxinidir}/.tox
black --config {[vars]pyproject_toml} {[vars]all_path} --exclude {[vars]tst_lib_path}
[testenv:fetch]
basepython = python3
deps =
commands =
{toxinidir}/fetch-libs.sh
[testenv:cookie]
basepython = python3
deps = -r{toxinidir}/cookie-requirements.txt
commands = /bin/true
[testenv:py3]
basepython = python3
deps =
{[testenv]deps}
-r{toxinidir}/requirements.txt
[testenv:py38]
basepython = python3.8
deps = {[testenv:py3]deps}
[testenv:py39]
basepython = python3.9
deps = {[testenv:py3]deps}
[testenv:py310]
basepython = python3.10
deps = {[testenv:py3]deps}
[testenv:pep8]
description = Alias for lint
deps = {[testenv:lint]deps}
commands = {[testenv:lint]commands}
[testenv:lint]
description = Check code against coding style standards
deps =
black
flake8<6
flake8-docstrings
flake8-copyright
flake8-builtins
pyproject-flake8
pep8-naming
isort
codespell
commands =
codespell {[vars]all_path}
# pflake8 wrapper supports config from pyproject.toml
pflake8 --exclude {[vars]tst_lib_path} --config {toxinidir}/pyproject.toml {[vars]all_path}
isort --check-only --diff {[vars]all_path} --skip-glob {[vars]tst_lib_path}
black --config {[vars]pyproject_toml} --check --diff {[vars]all_path} --exclude {[vars]tst_lib_path}
[testenv:cover]
basepython = python3
deps = {[testenv:py3]deps}
setenv =
PYTHON=coverage run
commands =
coverage erase
stestr run --slowest {posargs}
coverage combine
coverage html -d cover
coverage xml -o cover/coverage.xml
coverage report
[testenv:scenario]
description = Scenario tests
deps =
-r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
commands =
pytest -v --tb native {[vars]scenario_tst_path} --log-cli-level=INFO
[coverage:run]
branch = True
concurrency = multiprocessing
parallel = True
source =
.
omit =
.tox/*
unit_tests/*
[testenv:venv]
basepython = python3
commands = {posargs}
[flake8]
ignore = E226,E402,ANN101,ANN003,W504