← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/lpcraft:test-clean-environment into lpcraft:main

 

Colin Watson has proposed merging ~cjwatson/lpcraft:test-clean-environment into lpcraft:main.

Commit message:
Clean whole environment in LXD provider tests

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/lpcraft/+git/lpcraft/+merge/413709

tox 4 passes through proxy environment variables by default, so if they happened to be set in the calling environment then tests previously failed.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/lpcraft:test-clean-environment into lpcraft:main.
diff --git a/lpcraft/providers/tests/test_lxd.py b/lpcraft/providers/tests/test_lxd.py
index 408f15a..cc8255e 100644
--- a/lpcraft/providers/tests/test_lxd.py
+++ b/lpcraft/providers/tests/test_lxd.py
@@ -1,7 +1,6 @@
 # Copyright 2021 Canonical Ltd.  This software is licensed under the
 # GNU General Public License version 3 (see the file LICENSE).
 
-import os
 import re
 from pathlib import Path
 from typing import Optional
@@ -235,9 +234,7 @@ class TestLXDProvider(TestCase):
             ),
         )
 
-    @patch.dict(
-        os.environ, {"IGNORE": "sentinel", "PATH": "not-using-host-path"}
-    )
+    @patch("os.environ", {"IGNORE": "sentinel", "PATH": "not-using-host-path"})
     def test_get_command_environment_minimal(self):
         provider = self.makeLXDProvider()
 
@@ -245,8 +242,8 @@ class TestLXDProvider(TestCase):
 
         self.assertEqual({"PATH": _base_path}, env)
 
-    @patch.dict(
-        os.environ,
+    @patch(
+        "os.environ",
         {
             "IGNORE": "sentinel",
             "PATH": "not-using-host-path",
@@ -270,6 +267,7 @@ class TestLXDProvider(TestCase):
             env,
         )
 
+    @patch("os.environ", {"PATH": "not-using-host-path"})
     def test_launched_environment(self):
         expected_instance_name = "lpcraft-my-project-12345-focal-amd64"
         mock_lxc = Mock(spec=LXC)