From 775fd8f432f3a90e88415a73ca36de38c5980a50 Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Wed, 12 Jul 2023 11:11:09 +0200 Subject: [PATCH] tests: Fix import error for c23 module For some strange reason, it seems like using from module_a import module_b from module_b import module_c will not work... I guess any from imports must be an existing module and cannot be something brought in. Note the in this example module_b is usable just not importable. We have had some failing tests which I was able to reproduce locally. In this case it is regarding the mock -> python2 and unittest.mock -> python3 abstraction. One can use or print the imported mock, but cannot from x import y it. The solution is to just import all the from x import y within the version abstraction branch. It has been locally tested allowing mock to still be used. --- iotlabcli/tests/c23.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/iotlabcli/tests/c23.py b/iotlabcli/tests/c23.py index 7c61bc2..e8d14d6 100644 --- a/iotlabcli/tests/c23.py +++ b/iotlabcli/tests/c23.py @@ -34,13 +34,12 @@ from urllib2 import HTTPError import mock from cStringIO import StringIO + from mock import patch, Mock, mock_open # noqa elif version_info[0] == 3: # pragma: no cover # python3 from urllib.error import HTTPError from unittest import mock + from unittest.mock import patch, Mock, mock_open # noqa from io import StringIO else: # pragma: no cover raise ValueError(f'Unknown python version {version_info!r}') - -# pylint:disable=wrong-import-position -from mock import patch, Mock, mock_open # noqa