From 81152b0f438da9e1b1c0486f07faec835c3956af Mon Sep 17 00:00:00 2001 From: Ivan Chvets Date: Wed, 4 Jan 2023 15:04:19 -0500 Subject: [PATCH] fix: fixed tests https://github.com/canonical/minio-operator/issues/78 Summary of changes: - Fixed tests to match update library and ops. - Modified tox.ini to ignore appropriate directories. --- tests/unit/__init__.py | 10 ++++++++++ tests/unit/test_charm.py | 2 +- tox.ini | 8 ++++---- 3 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 tests/unit/__init__.py diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py new file mode 100644 index 0000000..95355c3 --- /dev/null +++ b/tests/unit/__init__.py @@ -0,0 +1,10 @@ +# +# Initialize unit tests +# + +"""Setup test environment for unit tests.""" + +import ops.testing + +# enable simulation of container networking +ops.testing.SIMULATE_CAN_CONNECT = True diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py index e631228..2686bb2 100644 --- a/tests/unit/test_charm.py +++ b/tests/unit/test_charm.py @@ -388,7 +388,6 @@ def test_generate_config_hash(config, hash_salt, expected_hash, harness): def test_prometheus_data_set(harness, mocker): harness.set_leader(True) harness.set_model_name("kubeflow") - harness.begin() mock_net_get = mocker.patch("ops.testing._TestingModelBackend.network_get") mocker.patch("ops.testing._TestingPebbleClient.list_files") @@ -406,6 +405,7 @@ def test_prometheus_data_set(harness, mocker): rel_id = harness.add_relation("metrics-endpoint", "otherapp") harness.add_relation_unit(rel_id, "otherapp/0") harness.update_relation_data(rel_id, "otherapp", {}) + harness.begin() assert json.loads(harness.get_relation_data(rel_id, harness.model.app.name)["scrape_jobs"])[0][ "static_configs" diff --git a/tox.ini b/tox.ini index 13f98ba..6f4132b 100644 --- a/tox.ini +++ b/tox.ini @@ -50,10 +50,10 @@ description = Apply coding style standards to code 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 --skip *.json.tmpl + 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 --skip *.json.tmpl # pflake8 wrapper supports config from pyproject.toml pflake8 {[vars]all_path} isort --check-only --diff {[vars]all_path}