Skip to content

Commit 5ff92dd

Browse files
committed
Error during pyocd plugin execution if pyocd is not installed
1 parent c678403 commit 5ff92dd

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/mbed_os_tools/test/host_tests_plugins/module_copy_pyocd.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@
1515

1616
import os
1717
from .host_test_plugins import HostTestPluginBase
18-
from pyocd.core.helpers import ConnectHelper
19-
from pyocd.flash.loader import FileProgrammer
2018

19+
try:
20+
from pyocd.core.helpers import ConnectHelper
21+
from pyocd.flash.loader import FileProgrammer
22+
PYOCD_PRESENT = True
23+
except ImportError:
24+
PYOCD_PRESENT = False
2125

2226
class HostTestPluginCopyMethod_pyOCD(HostTestPluginBase):
2327
# Plugin interface
@@ -44,6 +48,13 @@ def execute(self, capability, *args, **kwargs):
4448
@param kwargs Additional arguments
4549
@return Capability call return value
4650
"""
51+
if not PYOCD_PRESENT:
52+
self.print_plugin_error(
53+
'The "pyocd" feature is not installed. Please run '
54+
'"pip install mbed-os-tools[pyocd]" to enable the "pyocd" copy plugin.'
55+
)
56+
return False
57+
4758
if not self.check_parameters(capability, *args, **kwargs):
4859
return False
4960

src/mbed_os_tools/test/host_tests_plugins/module_reset_pyocd.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
# limitations under the License.
1515

1616
from .host_test_plugins import HostTestPluginBase
17-
from pyocd.core.helpers import ConnectHelper
17+
18+
try:
19+
from pyocd.core.helpers import ConnectHelper
20+
PYOCD_PRESENT = True
21+
except ImportError:
22+
PYOCD_PRESENT = False
1823

1924

2025
class HostTestPluginResetMethod_pyOCD(HostTestPluginBase):
@@ -48,6 +53,13 @@ def execute(self, capability, *args, **kwargs):
4853
@details Each capability e.g. may directly just call some command line program or execute building pythonic function
4954
@return Capability call return value
5055
"""
56+
if not PYOCD_PRESENT:
57+
self.print_plugin_error(
58+
'The "pyocd" feature is not installed. Please run '
59+
'"pip install mbed-os-tools[pyocd]" to enable the "pyocd" reset plugin.'
60+
)
61+
return False
62+
5163
if not kwargs['target_id']:
5264
self.print_plugin_error("Error: target_id not set")
5365
return False

0 commit comments

Comments
 (0)