From e95080f734c3247fa79187ac68ada1f5c92abe5f Mon Sep 17 00:00:00 2001 From: Tony Meyer Date: Thu, 5 Sep 2024 13:55:53 +1200 Subject: [PATCH] fix: avoid changing os.environ in Harness. --- ops/testing.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ops/testing.py b/ops/testing.py index 40d60fc4f..9c4d7c9a1 100644 --- a/ops/testing.py +++ b/ops/testing.py @@ -260,9 +260,10 @@ def __init__( actions: Optional[YAMLStringOrFile] = None, config: Optional[YAMLStringOrFile] = None, ): - if 'JUJU_VERSION' not in os.environ: - os.environ['JUJU_VERSION'] = '0.0.0' - self._juju_context = _JujuContext.from_dict(os.environ) + context_environ = os.environ.copy() + if 'JUJU_VERSION' not in context_environ: + context_environ['JUJU_VERSION'] = '0.0.0' + self._juju_context = _JujuContext.from_dict(context_environ) self._charm_cls = charm_cls self._charm: Optional[CharmType] = None self._charm_dir = 'no-disk-path' # this may be updated by _create_meta