Make mock import python 2.7 compatible

In python3.x mock is now part of unittest library.
For being still compatible with python 2.7 we need to
catch import error when trying to import unittest.mock.

Also add an __init__.py file in validations_common/library,
to allow all unit tests to import successfully.

This is similar to [1] for validations-libs.

[1]- https://review.opendev.org/716597

Change-Id: I6a81dc2640e9c4af3a07158bea95ebaec9fd466b
This commit is contained in:
Javier Pena 2020-04-13 18:25:23 +02:00 committed by Javier Peña
parent 99050941f4
commit 0f88309091
3 changed files with 10 additions and 3 deletions

View File

View File

@ -12,8 +12,12 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest.mock import MagicMock
from unittest.mock import patch
try:
from unittest.mock import MagicMock
from unittest.mock import patch
except ImportError:
from mock import MagicMock
from mock import patch
from validations_common.library.check_package_update import check_update
from validations_common.library.check_package_update import get_package_details

View File

@ -23,7 +23,10 @@ Tests for `reportentry` module.
import validations_common.library.reportentry as validation
from validations_common.tests import base
from unittest import mock
try:
from unittest import mock
except ImportError:
import mock
reason = "Reason #1"
recommendation = ['Recommendation #1']