From 0ac212591542fa20b4b07e6afae2a104914233f5 Mon Sep 17 00:00:00 2001 From: Pietro Pasotti Date: Fri, 16 Aug 2024 12:27:39 +0200 Subject: [PATCH] addressed pr comments --- lib/charms/tempo_k8s/v1/charm_tracing.py | 6 +++++- tests/scenario/test_a_charm_tracer_multi_import_warning.py | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/charms/tempo_k8s/v1/charm_tracing.py b/lib/charms/tempo_k8s/v1/charm_tracing.py index 788836e..7f418f9 100644 --- a/lib/charms/tempo_k8s/v1/charm_tracing.py +++ b/lib/charms/tempo_k8s/v1/charm_tracing.py @@ -338,7 +338,11 @@ def _get_tracer() -> Optional[Tracer]: if context_tracer := _get_tracer_from_context(ctx): logger.warning( "Tracer not found in `tracer` context var. " - "Verify that you're importing all `charm_tracing` symbols from the same module path." + "Verify that you're importing all `charm_tracing` symbols from the same module path. \n" + "For example, DO: `from charms.lib...charm_tracing import foo, bar`. \n" + "DONT: \n" + " \t - `from charms.lib...charm_tracing import foo` \n" + " \t - `from lib...charm_tracing import bar` \n" "For more info: https://python-notes.curiousefficiency.org/en/latest/python" "_concepts/import_traps.html#the-double-import-trap" ) diff --git a/tests/scenario/test_a_charm_tracer_multi_import_warning.py b/tests/scenario/test_a_charm_tracer_multi_import_warning.py index 268fd44..dfdbfd9 100644 --- a/tests/scenario/test_a_charm_tracer_multi_import_warning.py +++ b/tests/scenario/test_a_charm_tracer_multi_import_warning.py @@ -1,4 +1,4 @@ -# WARNING keep this test module on top of the scenario tests, else the +# WARNING ensure that this test module runs before any other scenario test file, else the # imports from previous tests will pollute the sys.modules and cause this test to fail. # I know this is horrible but yea, couldn't find a better way to fix the issue. Tried: # - delete from sys.modules all modules containing 'charms.tempo_k8s' @@ -8,7 +8,7 @@ from unittest.mock import patch # this test file is intentionally quite broken, don't modify the imports -# import autoinstrument and get_current_span from charms.[...] +# import autoinstrument from charms.[...] from charms.tempo_k8s.v1.charm_tracing import _autoinstrument as autoinstrument from ops import CharmBase from scenario import Context, State