From dbde8dfd5b27a2482df9ccca1c01e0a8aa7144bc Mon Sep 17 00:00:00 2001 From: Carl Csaposs Date: Tue, 7 Feb 2023 12:20:46 +0000 Subject: [PATCH] Update tox.ini (#100) Ported from https://github.com/canonical/charmcraft/pull/1010 --- CONTRIBUTING.md | 16 ++--- tests/integration/__init__.py | 2 + tests/integration/conftest.py | 4 +- tests/integration/helpers.py | 3 +- .../integration/high_availability/__init__.py | 2 + .../integration/high_availability/conftest.py | 4 +- .../high_availability_helpers.py | 2 +- .../high_availability/test_replication.py | 4 +- .../high_availability/test_self_healing.py | 5 +- tests/integration/read_charm_yaml.py | 2 +- tests/integration/relations/__init__.py | 2 + tests/integration/relations/test_database.py | 5 +- tests/integration/relations/test_db_router.py | 2 +- .../relations/test_relation_mysql_legacy.py | 2 +- tests/integration/relations/test_shared_db.py | 2 +- tests/integration/test_tls.py | 3 +- tests/unit/test_charm.py | 3 +- tests/unit/test_database.py | 3 +- tests/unit/test_db_router.py | 3 +- tests/unit/test_relation_mysql_legacy.py | 3 +- tests/unit/test_shared_db.py | 3 +- tox.ini | 58 +++++++++---------- 22 files changed, 73 insertions(+), 60 deletions(-) create mode 100644 tests/integration/__init__.py create mode 100644 tests/integration/high_availability/__init__.py create mode 100644 tests/integration/relations/__init__.py diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8e5a54fb4..ebc45b2a8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -21,21 +21,21 @@ this operator. ## Developing -You can use the environments created by `tox` for development: +You can create an environment for development with `tox`: ```shell -tox --notest -e unit -source .tox/unit/bin/activate +tox devenv -e integration +source venv/bin/activate ``` ### Testing ```shell -tox run -e fmt # update your code according to linting rules -tox run -e lint # code style -tox run -e unit # unit tests -tox run -m integration # integration tests -tox # runs 'lint' and 'unit' environments +tox run -e format # update your code according to linting rules +tox run -e lint # code style +tox run -e unit # unit tests +tox run -m integration # integration tests +tox # runs 'lint' and 'unit' environments ``` ## Build charm diff --git a/tests/integration/__init__.py b/tests/integration/__init__.py new file mode 100644 index 000000000..db3bfe1a6 --- /dev/null +++ b/tests/integration/__init__.py @@ -0,0 +1,2 @@ +# Copyright 2023 Canonical Ltd. +# See LICENSE file for licensing details. diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 5873804fc..ea2e114ac 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -8,8 +8,8 @@ import pytest from pytest_operator.plugin import OpsTest -from tests.integration.integration_constants import SERIES_TO_VERSION -from tests.integration.read_charm_yaml import get_base_versions, get_charm_name +from .integration_constants import SERIES_TO_VERSION +from .read_charm_yaml import get_base_versions, get_charm_name def pytest_addoption(parser): diff --git a/tests/integration/helpers.py b/tests/integration/helpers.py index 5d3a54639..19c63b058 100644 --- a/tests/integration/helpers.py +++ b/tests/integration/helpers.py @@ -22,7 +22,8 @@ from tenacity import RetryError, Retrying, retry, stop_after_attempt, wait_fixed from constants import SERVER_CONFIG_USERNAME -from tests.integration.connector import MysqlConnector + +from .connector import MysqlConnector logger = logging.getLogger(__name__) diff --git a/tests/integration/high_availability/__init__.py b/tests/integration/high_availability/__init__.py new file mode 100644 index 000000000..db3bfe1a6 --- /dev/null +++ b/tests/integration/high_availability/__init__.py @@ -0,0 +1,2 @@ +# Copyright 2023 Canonical Ltd. +# See LICENSE file for licensing details. diff --git a/tests/integration/high_availability/conftest.py b/tests/integration/high_availability/conftest.py index cf65fdcab..748920f75 100644 --- a/tests/integration/high_availability/conftest.py +++ b/tests/integration/high_availability/conftest.py @@ -5,9 +5,7 @@ import pytest from pytest_operator.plugin import OpsTest -from tests.integration.high_availability.high_availability_helpers import ( - get_application_name, -) +from .high_availability_helpers import get_application_name @pytest.fixture() diff --git a/tests/integration/high_availability/high_availability_helpers.py b/tests/integration/high_availability/high_availability_helpers.py index 6ccf431df..f36682b76 100644 --- a/tests/integration/high_availability/high_availability_helpers.py +++ b/tests/integration/high_availability/high_availability_helpers.py @@ -10,7 +10,7 @@ from pytest_operator.plugin import OpsTest from tenacity import RetryError, Retrying, stop_after_delay, wait_fixed -from tests.integration.helpers import ( +from ..helpers import ( execute_queries_on_unit, generate_random_string, get_cluster_status, diff --git a/tests/integration/high_availability/test_replication.py b/tests/integration/high_availability/test_replication.py index b280c112a..33c28fcc2 100644 --- a/tests/integration/high_availability/test_replication.py +++ b/tests/integration/high_availability/test_replication.py @@ -10,7 +10,7 @@ import yaml from pytest_operator.plugin import OpsTest -from tests.integration.helpers import ( +from ..helpers import ( app_name, cluster_name, execute_queries_on_unit, @@ -20,7 +20,7 @@ get_server_config_credentials, scale_application, ) -from tests.integration.high_availability.high_availability_helpers import ( +from .high_availability_helpers import ( clean_up_database_and_table, ensure_all_units_continuous_writes_incrementing, ensure_n_online_mysql_members, diff --git a/tests/integration/high_availability/test_self_healing.py b/tests/integration/high_availability/test_self_healing.py index 20433d666..791ed4a94 100644 --- a/tests/integration/high_availability/test_self_healing.py +++ b/tests/integration/high_availability/test_self_healing.py @@ -12,7 +12,8 @@ from tenacity import RetryError, Retrying, stop_after_attempt, wait_fixed from constants import CLUSTER_ADMIN_USERNAME, SERVER_CONFIG_USERNAME -from tests.integration.helpers import ( + +from ..helpers import ( cut_network_from_unit, execute_queries_on_unit, get_controller_machine, @@ -31,7 +32,7 @@ wait_network_restore, write_random_chars_to_test_table, ) -from tests.integration.high_availability.high_availability_helpers import ( +from .high_availability_helpers import ( clean_up_database_and_table, ensure_all_units_continuous_writes_incrementing, ensure_n_online_mysql_members, diff --git a/tests/integration/read_charm_yaml.py b/tests/integration/read_charm_yaml.py index c210417fe..961919958 100644 --- a/tests/integration/read_charm_yaml.py +++ b/tests/integration/read_charm_yaml.py @@ -8,7 +8,7 @@ import yaml -from tests.integration.integration_constants import SERIES_TO_VERSION +from .integration_constants import SERIES_TO_VERSION def get_base_versions(path_to_charmcraft_yaml: Path) -> list[str]: diff --git a/tests/integration/relations/__init__.py b/tests/integration/relations/__init__.py new file mode 100644 index 000000000..db3bfe1a6 --- /dev/null +++ b/tests/integration/relations/__init__.py @@ -0,0 +1,2 @@ +# Copyright 2023 Canonical Ltd. +# See LICENSE file for licensing details. diff --git a/tests/integration/relations/test_database.py b/tests/integration/relations/test_database.py index d16c4825f..40bba5764 100644 --- a/tests/integration/relations/test_database.py +++ b/tests/integration/relations/test_database.py @@ -17,7 +17,9 @@ ROOT_USERNAME, SERVER_CONFIG_USERNAME, ) -from tests.integration.helpers import ( +from utils import generate_random_password + +from ..helpers import ( check_read_only_endpoints, execute_queries_on_unit, fetch_credentials, @@ -29,7 +31,6 @@ rotate_credentials, scale_application, ) -from utils import generate_random_password logger = logging.getLogger(__name__) diff --git a/tests/integration/relations/test_db_router.py b/tests/integration/relations/test_db_router.py index 36b490a1e..4502c7ab7 100644 --- a/tests/integration/relations/test_db_router.py +++ b/tests/integration/relations/test_db_router.py @@ -11,7 +11,7 @@ import yaml from pytest_operator.plugin import OpsTest -from tests.integration.helpers import ( +from ..helpers import ( execute_queries_on_unit, get_server_config_credentials, scale_application, diff --git a/tests/integration/relations/test_relation_mysql_legacy.py b/tests/integration/relations/test_relation_mysql_legacy.py index c59cce211..9057679f1 100644 --- a/tests/integration/relations/test_relation_mysql_legacy.py +++ b/tests/integration/relations/test_relation_mysql_legacy.py @@ -10,7 +10,7 @@ import yaml from pytest_operator.plugin import OpsTest -from tests.integration.helpers import ( +from ..helpers import ( get_legacy_mysql_credentials, instance_ip, is_connection_possible, diff --git a/tests/integration/relations/test_shared_db.py b/tests/integration/relations/test_shared_db.py index 52b2b3a74..273670edf 100644 --- a/tests/integration/relations/test_shared_db.py +++ b/tests/integration/relations/test_shared_db.py @@ -10,7 +10,7 @@ import yaml from pytest_operator.plugin import OpsTest -from tests.integration.helpers import ( +from ..helpers import ( execute_queries_on_unit, get_primary_unit, get_server_config_credentials, diff --git a/tests/integration/test_tls.py b/tests/integration/test_tls.py index b32a6c599..c063b62c9 100644 --- a/tests/integration/test_tls.py +++ b/tests/integration/test_tls.py @@ -9,7 +9,8 @@ from pytest_operator.plugin import OpsTest from constants import CLUSTER_ADMIN_USERNAME, TLS_SSL_CERT_FILE -from tests.integration.helpers import ( + +from .helpers import ( app_name, get_process_pid, get_system_user_password, diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py index bfdb2eec9..a942ce451 100644 --- a/tests/unit/test_charm.py +++ b/tests/unit/test_charm.py @@ -15,7 +15,8 @@ from tenacity import Retrying, stop_after_attempt from charm import MySQLOperatorCharm -from tests.unit.helpers import patch_network_get + +from .helpers import patch_network_get class TestCharm(unittest.TestCase): diff --git a/tests/unit/test_database.py b/tests/unit/test_database.py index 7dc8e4036..b34f8f866 100644 --- a/tests/unit/test_database.py +++ b/tests/unit/test_database.py @@ -9,7 +9,8 @@ from charm import MySQLOperatorCharm from constants import DB_RELATION_NAME -from tests.unit.helpers import patch_network_get + +from .helpers import patch_network_get class TestDatase(unittest.TestCase): diff --git a/tests/unit/test_db_router.py b/tests/unit/test_db_router.py index a800c6895..6ab03934e 100644 --- a/tests/unit/test_db_router.py +++ b/tests/unit/test_db_router.py @@ -13,7 +13,8 @@ from ops.testing import Harness from charm import MySQLOperatorCharm -from tests.unit.helpers import patch_network_get + +from .helpers import patch_network_get class TestDBRouter(unittest.TestCase): diff --git a/tests/unit/test_relation_mysql_legacy.py b/tests/unit/test_relation_mysql_legacy.py index 34c057ef8..4e6a69aaf 100644 --- a/tests/unit/test_relation_mysql_legacy.py +++ b/tests/unit/test_relation_mysql_legacy.py @@ -8,7 +8,8 @@ from charm import MySQLOperatorCharm from constants import LEGACY_MYSQL, PEER -from tests.unit.helpers import patch_network_get + +from .helpers import patch_network_get class TestMariaDBRelation(unittest.TestCase): diff --git a/tests/unit/test_shared_db.py b/tests/unit/test_shared_db.py index 187b8d61b..3c65d3f0f 100644 --- a/tests/unit/test_shared_db.py +++ b/tests/unit/test_shared_db.py @@ -10,7 +10,8 @@ from charm import MySQLOperatorCharm from constants import LEGACY_DB_SHARED -from tests.unit.helpers import patch_network_get + +from .helpers import patch_network_get class TestSharedDBRelation(unittest.TestCase): diff --git a/tox.ini b/tox.ini index 7d9c1668e..e99ef1aaa 100644 --- a/tox.ini +++ b/tox.ini @@ -2,32 +2,32 @@ # See LICENSE file for licensing details. [tox] -skipsdist=True +no_package = True skip_missing_interpreters = True -envlist = lint, unit +env_list = lint, unit labels = integration = integration-ha, integration-db-router, integration-shared-db, \ integration-database, integration-mysql-interface, integration-healing, \ integration-tls [vars] -src_path = {toxinidir}/src -tests_path = {toxinidir}/tests -lib_path = {toxinidir}/lib/charms/mysql +src_path = {tox_root}/src +tests_path = {tox_root}/tests +lib_path = {tox_root}/lib/charms/mysql all_path = {[vars]src_path} {[vars]tests_path} {[vars]lib_path} [testenv] -setenv = - PYTHONPATH = {toxinidir}:{toxinidir}/lib:{[vars]src_path} - PYTHONBREAKPOINT=ipdb.set_trace - PY_COLORS=1 -passenv = - CI - PYTHONPATH - CHARM_BUILD_DIR - MODEL_SETTINGS - -[testenv:fmt] +set_env = + PYTHONPATH = {tox_root}/lib:{[vars]src_path} + PYTHONBREAKPOINT=ipdb.set_trace + PY_COLORS=1 +pass_env = + CI + PYTHONPATH + CHARM_BUILD_DIR + MODEL_SETTINGS + +[testenv:format] description = Apply coding style standards to code deps = black @@ -53,9 +53,9 @@ allowlist_externals = /bin/bash commands = # uncomment the following line if this charm owns a lib # codespell {[vars]lib_path} - codespell {toxinidir} --skip {toxinidir}/.git --skip {toxinidir}/.tox \ - --skip {toxinidir}/build --skip {toxinidir}/lib --skip {toxinidir}/venv \ - --skip {toxinidir}/.mypy_cache --skip {toxinidir}/icon.svg + codespell {tox_root} --skip {tox_root}/.git --skip {tox_root}/.tox \ + --skip {tox_root}/build --skip {tox_root}/lib --skip {tox_root}/venv \ + --skip {tox_root}/.mypy_cache --skip {tox_root}/icon.svg # pflake8 wrapper supports config from pyproject.toml pflake8 {[vars]all_path} isort --check-only --diff {[vars]all_path} @@ -67,7 +67,7 @@ description = Run unit tests deps = pytest coverage[toml] - -r{toxinidir}/requirements.txt + -r {tox_root}/requirements.txt commands = coverage run --source={[vars]src_path},{[vars]lib_path} \ -m pytest -v --tb native -s {posargs} {[vars]tests_path}/unit @@ -77,7 +77,7 @@ commands = description = Create build matrix for integration tests deps = pyyaml -passenv = GITHUB_OUTPUT +pass_env = GITHUB_OUTPUT commands = python -c "from tests.integration.read_charm_yaml import create_build_matrix; create_build_matrix()" @@ -89,7 +89,7 @@ deps = pytest pytest-operator pyyaml - -r{toxinidir}/requirements.txt + -r {tox_root}/requirements.txt commands = pytest -v --tb native --log-cli-level=INFO -s {posargs} {[vars]tests_path}/integration/high_availability/test_replication.py @@ -101,7 +101,7 @@ deps = pytest pytest-operator pyyaml - -r{toxinidir}/requirements.txt + -r {tox_root}/requirements.txt commands = pytest -v --tb native --log-cli-level=INFO -s {posargs} {[vars]tests_path}/integration/relations/test_db_router.py @@ -113,7 +113,7 @@ deps = pytest pytest-operator pyyaml - -r{toxinidir}/requirements.txt + -r {tox_root}/requirements.txt commands = pytest -v --tb native --log-cli-level=INFO -s {posargs} {[vars]tests_path}/integration/relations/test_shared_db.py @@ -125,7 +125,7 @@ deps = pytest pytest-operator pyyaml - -r{toxinidir}/requirements.txt + -r {tox_root}/requirements.txt commands = pytest -v --tb native --log-cli-level=INFO -s {posargs} {[vars]tests_path}/integration/relations/test_database.py @@ -137,7 +137,7 @@ deps = pytest pytest-operator pyyaml - -r{toxinidir}/requirements.txt + -r {tox_root}/requirements.txt commands = pytest -v --tb native --log-cli-level=INFO -s {posargs} {[vars]tests_path}/integration/relations/test_relation_mysql_legacy.py @@ -149,7 +149,7 @@ deps = pytest pytest-operator pyyaml - -r{toxinidir}/requirements.txt + -r {tox_root}/requirements.txt commands = pytest -v --tb native --log-cli-level=INFO -s {posargs} {[vars]tests_path}/integration/high_availability/test_self_healing.py @@ -161,7 +161,7 @@ deps = pytest pytest-operator pyyaml - -r{toxinidir}/requirements.txt + -r {tox_root}/requirements.txt commands = pytest -v --tb native --log-cli-level=INFO -s {posargs} {[vars]tests_path}/integration/test_tls.py @@ -175,7 +175,7 @@ deps = pdbpp pytest-operator pyyaml - -r{toxinidir}/requirements.txt + -r {tox_root}/requirements.txt commands = pytest -v --tb native --ignore={[vars]tests_path}/unit --log-cli-level=INFO -s {posargs} -m "dev"