It was found that the modules test_actions_openstack_upgrade and test_actions_package_upgrade were mocking different classes and functions right before importing the modules under test (openstack_upgrade and package_upgrade respectively), although these mocks weren't being reset making tests executions coming after them to get benefitted (or impacted) by the mocks in memory. This patch takes advantage of mock.patch() decorator at the class level and importlib.reload() to make sure the mocks don't outsurvive the module. When the teardown was in place it was found a different set of functions that were relying on that mocking, so they were patched to allow the tests run in the expected (mock'ed) environment. Summary of changes: - Move get_availability_zone() to contexts module, nova_compute_utils depends on nova_compute_context, the latter shouldn't be importing code from the former since it breaks the layering, even when the import is being done within a function's body. - Mock env variable JUJU_UNIT_NAME per test case, the tests defined in the test_nova_compute_utils and test_nova_compute_contexts were relying on the leakage of mocks set by other test modules, this makes them run in an isolated fashion. - Move update_nrpe_config testing to its own class, the main class NovaComputeRelationsTests mocks the function update_nrpe_config() making it difficult to test it in a test method, hence making the test part of its own class it's posible to not mock the function and correctly runs its implementation. - Teardown mocks made at import level. Func-Test-Pr: https://github.com/openstack-charmers/zaza-openstack-tests/pull/997 Change-Id: I4468ef1a0619befc75c6af2bad8df316125a7cf5
2.8 KiB
2.8 KiB