Improve platform mocking

Patch out charmhelpers.osplatform.get_platform() and
charmhelpers.core.host.lsb_release() globally in the unit tests to
insulate the unit tests from the platform that the unit tests are being
run on.

Change-Id: I27979aaeec8040b8cd5c07e5ad12a6ca8544278c
This commit is contained in:
Alex Kavanagh
2023-10-24 18:02:12 +01:00
parent af1bfc7eda
commit ea0ef6d32e

View File

@ -14,6 +14,7 @@
import os
import sys
from unittest.mock import patch
_path = os.path.dirname(os.path.realpath(__file__))
_root = os.path.abspath(os.path.join(_path, '..'))
@ -27,3 +28,15 @@ def _add_path(path):
_add_path(_path)
_add_path('actions')
_add_path('hooks')
# Patch out lsb_release() and get_platform() as unit tests should be fully
# insulated from the underlying platform. Unit tests assume that the system is
# ubuntu jammy.
patch(
'charmhelpers.osplatform.get_platform', return_value='ubuntu'
).start()
patch(
'charmhelpers.core.host.lsb_release',
return_value={
'DISTRIB_CODENAME': 'jammy'
}).start()