Skip to content

Commit c25890d

Browse files
committed
call pkg_patcher only when it's needed
1 parent 3ba64a4 commit c25890d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

opentelemetry-instrumentation/tests/test_bootstrap.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,11 @@ def setUp(self):
6363
super().setUp()
6464
self.mock_pip_check = self.pip_check_patcher.start()
6565
self.mock_pip_install = self.pip_install_patcher.start()
66-
self.pkg_patcher.start()
6766

6867
def tearDown(self):
6968
super().tearDown()
7069
self.pip_check_patcher.stop()
7170
self.pip_install_patcher.stop()
72-
self.pkg_patcher.stop()
7371

7472
@patch("sys.argv", ["bootstrap", "-a", "pipenv"])
7573
def test_run_unknown_cmd(self):
@@ -78,25 +76,28 @@ def test_run_unknown_cmd(self):
7876

7977
@patch("sys.argv", ["bootstrap", "-a", "requirements"])
8078
def test_run_cmd_print(self):
79+
self.pkg_patcher.start()
8180
with patch("sys.stdout", new=StringIO()) as fake_out:
8281
bootstrap.run()
8382
self.assertEqual(
8483
fake_out.getvalue(),
8584
"\n".join(self.installed_libraries) + "\n",
8685
)
86+
self.pkg_patcher.stop()
8787

8888
@patch("sys.argv", ["bootstrap", "-a", "install"])
8989
def test_run_cmd_install(self):
90+
self.pkg_patcher.start()
9091
bootstrap.run()
9192
self.mock_pip_install.assert_has_calls(
9293
[call(i) for i in self.installed_libraries],
9394
any_order=True,
9495
)
9596
self.mock_pip_check.assert_called_once()
97+
self.pkg_patcher.stop()
9698

9799
@patch("sys.argv", ["bootstrap", "-a", "install"])
98100
def test_can_override_available_libraries(self):
99-
self.pkg_patcher.stop()
100101
bootstrap.run(libraries=[])
101102
self.mock_pip_install.assert_has_calls(
102103
[call(i) for i in default_instrumentations],
@@ -106,7 +107,6 @@ def test_can_override_available_libraries(self):
106107

107108
@patch("sys.argv", ["bootstrap", "-a", "install"])
108109
def test_can_override_available_default_instrumentations(self):
109-
self.pkg_patcher.stop()
110110
with patch(
111111
"opentelemetry.instrumentation.bootstrap._is_installed",
112112
return_value=True,

0 commit comments

Comments
 (0)