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: Ic558fa7bab80b0dabc3e5a06d7494e2688c027b3
This commit is contained in:
Alex Kavanagh
2023-10-24 16:15:39 +01:00
parent cf1ffe6866
commit 89d7e78998

View File

@@ -15,6 +15,9 @@
import os
import sys
from unittest.mock import patch
_path = os.path.dirname(os.path.realpath(__file__))
_parent = os.path.abspath(os.path.join(_path, '..'))
@@ -25,3 +28,15 @@ def _add_path(path):
_add_path(_parent)
# 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()