Skip to content

Commit

Permalink
Merge pull request #3267 from candlepin/mhorky/profile-mock-failures
Browse files Browse the repository at this point in the history
Prevent Mock failures for ModulesProfile tests
  • Loading branch information
ptoscano authored May 11, 2023
2 parents 85298ce + d9f6526 commit ce9c157
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
7 changes: 0 additions & 7 deletions test/cloud_what/test_cloud_what.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ def setUp(self):
"""
Set up two mocks that are used in all tests
"""
aws.AWSCloudProvider._instance = None
aws.AWSCloudProvider._initialized = False
azure.AzureCloudProvider._instance = None
azure.AzureCloudProvider._initialized = False
gcp.GCPCloudProvider._instance = None
gcp.GCPCloudProvider._initialized = False

custom_facts_collector_patcher = patch("cloud_what.provider.CustomFactsCollector")
self.custom_facts_collector_mock = custom_facts_collector_patcher.start()
self.custom_facts_collector_instance = Mock()
Expand Down
9 changes: 9 additions & 0 deletions test/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
# just log py.warnings (and pygtk warnings in particular)
import logging

from cloud_what.providers import aws, azure, gcp

try:
# 2.7+
logging.captureWarnings(True)
Expand Down Expand Up @@ -273,6 +275,13 @@ def tearDown(self):
# the write_tempfile() method in this class.
f.close()

aws.AWSCloudProvider._instance = None
aws.AWSCloudProvider._initialized = False
azure.AzureCloudProvider._instance = None
azure.AzureCloudProvider._initialized = False
gcp.GCPCloudProvider._instance = None
gcp.GCPCloudProvider._initialized = False

def write_tempfile(self, contents):
"""
Write out a tempfile and append it to the list of those to be
Expand Down
10 changes: 10 additions & 0 deletions test/rhsm/unit/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from unittest import mock
from unittest.mock import patch

from cloud_what.providers import aws, azure, gcp

from rhsm.profile import ModulesProfile, EnabledReposProfile


Expand All @@ -38,6 +40,14 @@ def setUp(self) -> None:
self.cloud_provider_mock.get_cloud_provider = mock.Mock(return_value=None)
self.addCleanup(cloud_provider_patcher.stop)

def tearDown(self) -> None:
aws.AWSCloudProvider._instance = None
aws.AWSCloudProvider._initialized = False
azure.AzureCloudProvider._instance = None
azure.AzureCloudProvider._initialized = False
gcp.GCPCloudProvider._instance = None
gcp.GCPCloudProvider._initialized = False

def test_default_status(self) -> None:
"""
Test the case, when module is not enabled nor disabled. The status of module
Expand Down
8 changes: 8 additions & 0 deletions test/rhsmlib/facts/test_cloud_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ def setUp(self):
self.requests_mock = self.requests_patcher.start()
self.addCleanup(self.requests_patcher.stop)

def tearDown(self) -> None:
aws.AWSCloudProvider._instance = None
aws.AWSCloudProvider._initialized = False
azure.AzureCloudProvider._instance = None
azure.AzureCloudProvider._initialized = False
gcp.GCPCloudProvider._instance = None
gcp.GCPCloudProvider._initialized = False

@patch("cloud_what.providers.aws.requests.Session", name="test_get_aws_facts.mock_session_class")
def test_get_aws_facts(self, mock_session_class):
"""
Expand Down
2 changes: 1 addition & 1 deletion test/test_auto_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def mock_prepare_request(request):


class TestAutomaticRegistration(unittest.TestCase):
def setUp(self):
def tearDown(self):
aws.AWSCloudProvider._instance = None
aws.AWSCloudProvider._initialized = False
azure.AzureCloudProvider._instance = None
Expand Down

0 comments on commit ce9c157

Please sign in to comment.