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: I6807128492cb184de3ef5f454d0ea745246b242e
This commit is contained in:
Alex Kavanagh 2023-10-24 11:39:15 +01:00
parent 8b366fbf6b
commit 39462317b6
1 changed files with 12 additions and 0 deletions

View File

@ -48,3 +48,15 @@ sys.modules['cinder.db.sqlalchemy.api'] = cinder.db.sqlalchemy.api
mock_apt = mock.MagicMock()
sys.modules['apt'] = mock_apt
mock_apt.apt_pkg = mock.MagicMock()
# 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.
mock.patch(
'charmhelpers.osplatform.get_platform', return_value='ubuntu'
).start()
mock.patch(
'charmhelpers.core.host.lsb_release',
return_value={
'DISTRIB_CODENAME': 'jammy'
}).start()