Skip to content

Commit 7b18467

Browse files
committed
Dev: unittests: avoid using importlib.reload to reload module
And patch those functions decorated by @memoize with their original version, which is available as <decorated_function>.__wrapped__
1 parent 1814a37 commit 7b18467

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

test/unittests/test_utils.py

+4-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import os
88
import socket
99
import re
10-
import importlib
1110
import subprocess
1211
import unittest
1312
import pytest
@@ -20,12 +19,6 @@
2019

2120
logging.basicConfig(level=logging.DEBUG)
2221

23-
def setup_function():
24-
utils._ip_for_cloud = None
25-
# Mock memoize method and reload the module under test later with imp
26-
mock.patch('crmsh.utils.memoize', lambda x: x).start()
27-
importlib.reload(utils)
28-
2922

3023
@mock.patch("crmsh.utils.get_stdout_stderr")
3124
def test_print_cluster_nodes(mock_run):
@@ -547,7 +540,7 @@ def test_detect_cloud_no_cmd(mock_is_program):
547540
def test_detect_cloud_aws(mock_is_program, mock_aws):
548541
mock_is_program.return_value = True
549542
mock_aws.return_value = True
550-
assert utils.detect_cloud() == constants.CLOUD_AWS
543+
assert utils.detect_cloud.__wrapped__() == constants.CLOUD_AWS
551544
mock_is_program.assert_called_once_with("dmidecode")
552545
mock_aws.assert_called_once_with()
553546

@@ -558,7 +551,7 @@ def test_detect_cloud_azure(mock_is_program, mock_aws, mock_azure):
558551
mock_is_program.return_value = True
559552
mock_aws.return_value = False
560553
mock_azure.return_value = True
561-
assert utils.detect_cloud() == constants.CLOUD_AZURE
554+
assert utils.detect_cloud.__wrapped__() == constants.CLOUD_AZURE
562555
mock_is_program.assert_called_once_with("dmidecode")
563556
mock_aws.assert_called_once_with()
564557
mock_azure.assert_called_once_with()
@@ -572,7 +565,7 @@ def test_detect_cloud_gcp(mock_is_program, mock_aws, mock_azure, mock_gcp):
572565
mock_aws.return_value = False
573566
mock_azure.return_value = False
574567
mock_gcp.return_value = True
575-
assert utils.detect_cloud() == constants.CLOUD_GCP
568+
assert utils.detect_cloud.__wrapped__() == constants.CLOUD_GCP
576569
mock_is_program.assert_called_once_with("dmidecode")
577570
mock_aws.assert_called_once_with()
578571
mock_azure.assert_called_once_with()
@@ -1681,6 +1674,7 @@ def test_handle_role_for_ocf_1_1(mock_support, mock_warn):
16811674
def test_handle_role_for_ocf_1_1_convert_new(mock_support, mock_info):
16821675
config.core.OCF_1_1_SUPPORT = True
16831676
mock_support.return_value = True
1677+
utils.auto_convert_role = True
16841678
assert utils.handle_role_for_ocf_1_1("Master") == "Promoted"
16851679
mock_support.assert_called_once_with()
16861680
mock_info.assert_called_once_with('Convert deprecated "%s" to "%s"', "Master", "Promoted")

0 commit comments

Comments
 (0)