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: Ice2a2d2379349c8cf7d77027cbca78b19e9d72d1 func-test-pr: https://github.com/openstack-charmers/zaza-openstack-tests/pull/1170
This commit is contained in:
parent
068240f115
commit
d00d011c18
38
tox.ini
38
tox.ini
@ -23,9 +23,9 @@ skip_missing_interpreters = False
|
||||
# lead to fetching the latest pip in the func* tox targets, see
|
||||
# https://stackoverflow.com/a/38133283
|
||||
requires =
|
||||
pip < 20.3
|
||||
virtualenv < 20.0
|
||||
setuptools < 50.0.0
|
||||
pip
|
||||
virtualenv
|
||||
setuptools
|
||||
|
||||
# NOTE: https://wiki.canonical.com/engineering/OpenStack/InstallLatestToxOnOsci
|
||||
minversion = 3.18.0
|
||||
@ -34,13 +34,16 @@ minversion = 3.18.0
|
||||
setenv = VIRTUAL_ENV={envdir}
|
||||
PYTHONHASHSEED=0
|
||||
CHARM_DIR={envdir}
|
||||
install_command =
|
||||
{toxinidir}/pip.sh install {opts} {packages}
|
||||
commands = stestr run --slowest {posargs}
|
||||
allowlist_externals =
|
||||
charmcraft
|
||||
rename.sh
|
||||
passenv = HOME TERM CS_* OS_* TEST_*
|
||||
{toxinidir}/rename.sh
|
||||
passenv =
|
||||
HOME
|
||||
TERM
|
||||
CS_*
|
||||
OS_*
|
||||
TEST_*
|
||||
deps = -r{toxinidir}/test-requirements.txt
|
||||
|
||||
[testenv:build]
|
||||
@ -50,21 +53,25 @@ commands =
|
||||
charmcraft clean
|
||||
charmcraft -v pack
|
||||
{toxinidir}/rename.sh
|
||||
charmcraft clean
|
||||
|
||||
[testenv:py310]
|
||||
basepython = python3.10
|
||||
deps = -r{toxinidir}/requirements.txt
|
||||
-r{toxinidir}/test-requirements.txt
|
||||
deps =
|
||||
-r{toxinidir}/requirements.txt
|
||||
-r{toxinidir}/test-requirements.txt
|
||||
|
||||
[testenv:py3]
|
||||
basepython = python3
|
||||
deps = -r{toxinidir}/requirements.txt
|
||||
-r{toxinidir}/test-requirements.txt
|
||||
deps =
|
||||
-r{toxinidir}/requirements.txt
|
||||
-r{toxinidir}/test-requirements.txt
|
||||
|
||||
[testenv:pep8]
|
||||
basepython = python3
|
||||
deps = flake8==3.9.2
|
||||
git+https://github.com/juju/charm-tools.git
|
||||
deps =
|
||||
flake8==3.9.2
|
||||
git+https://github.com/juju/charm-tools.git
|
||||
commands = flake8 {posargs} hooks unit_tests tests actions lib files
|
||||
charm-proof
|
||||
|
||||
@ -72,8 +79,9 @@ commands = flake8 {posargs} hooks unit_tests tests actions lib files
|
||||
# Technique based heavily upon
|
||||
# https://github.com/openstack/nova/blob/master/tox.ini
|
||||
basepython = python3
|
||||
deps = -r{toxinidir}/requirements.txt
|
||||
-r{toxinidir}/test-requirements.txt
|
||||
deps =
|
||||
-r{toxinidir}/requirements.txt
|
||||
-r{toxinidir}/test-requirements.txt
|
||||
setenv =
|
||||
{[testenv]setenv}
|
||||
PYTHON=coverage run
|
||||
|
@ -13,5 +13,21 @@
|
||||
# limitations under the License.
|
||||
|
||||
import sys
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
sys.path.append('hooks')
|
||||
sys.path.append('unit_tests')
|
||||
|
||||
|
||||
# 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()
|
||||
|
Loading…
Reference in New Issue
Block a user