@@ -322,10 +322,10 @@ def exec(
322
322
juju_context = _JujuContext .from_dict (env )
323
323
# We need to set JUJU_VERSION in os.environ, because charms may use
324
324
# `JujuVersion.from_environ()` to get the (simulated) Juju version.
325
- # All of the other environment variables are exposed to the charm
326
- # through the framework machinery, so don't require this .
327
- previous_juju_version = os .environ .get ( "JUJU_VERSION" )
328
- os .environ [ "JUJU_VERSION" ] = env [ "JUJU_VERSION" ]
325
+ # For consistency, we put all the other ones there too, although we'd
326
+ # like to change this in the future .
327
+ previous_env = os .environ .copy ( )
328
+ os .environ . update ( env )
329
329
330
330
logger .info (" - entering ops.main (mocked)" )
331
331
from ._ops_main_mock import Ops # noqa: F811
@@ -352,10 +352,14 @@ def exec(
352
352
) from e
353
353
354
354
finally :
355
- if previous_juju_version is None :
356
- del os .environ ["JUJU_VERSION" ]
357
- else :
358
- os .environ ["JUJU_VERSION" ] = previous_juju_version
355
+ for key , value in os .environ .copy ().items ():
356
+ if key in previous_env :
357
+ os .environ [key ] = value
358
+ else :
359
+ del os .environ [key ]
360
+ for key , value in previous_env .items ():
361
+ if key not in os .environ :
362
+ os .environ [key ] = value
359
363
logger .info (" - exited ops.main" )
360
364
361
365
context .emitted_events .extend (captured )
0 commit comments