diff options
author | Stephen Finucane <sfinucan@redhat.com> | 2022-06-20 13:18:04 +0100 |
---|---|---|
committer | Stephen Finucane <sfinucan@redhat.com> | 2022-06-20 13:29:52 +0100 |
commit | 0916df35f9d391639d935d89f28554852fdf07be (patch) | |
tree | 5da6f9526bce38e87203179c3625215141956e2c | |
parent | c4f2e2e1db55172aeb5e3a610d3b6ec0df4383d5 (diff) | |
download | keystone-0916df35f9d391639d935d89f28554852fdf07be.tar.gz |
tests: Don't monkeypatch functions
We were inadvertently monkeypatching a variety of functions in
'keystone.common.sql.upgrades'. We should be configuring mocks for these
that we teardown at the end of the test. This has been an issue since we
first added these tests way back in change
I9f138fe0bcbf5ffbb98e6fcebd7d897329a301b7. Fix it now.
Change-Id: I185420e6d16276e7d184146f6a38b098abc00b25
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Suggested-by: Mike Bayer <mike_mp@zzzcomputing.com>
-rw-r--r-- | keystone/tests/unit/test_cli.py | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/keystone/tests/unit/test_cli.py b/keystone/tests/unit/test_cli.py index c94d8c196..2f9bed064 100644 --- a/keystone/tests/unit/test_cli.py +++ b/keystone/tests/unit/test_cli.py @@ -754,18 +754,28 @@ class CliDBSyncTestCase(unit.BaseTestCase): self.version = None def setUp(self): - super(CliDBSyncTestCase, self).setUp() + super().setUp() self.config_fixture = self.useFixture(oslo_config.fixture.Config(CONF)) self.config_fixture.register_cli_opt(cli.command_opt) - upgrades.offline_sync_database_to_version = mock.Mock() - upgrades.expand_schema = mock.Mock() - upgrades.migrate_data = mock.Mock() - upgrades.contract_schema = mock.Mock() + + self.patchers = patchers = [ + mock.patch.object(upgrades, "offline_sync_database_to_version"), + mock.patch.object(upgrades, "expand_schema"), + mock.patch.object(upgrades, "migrate_data"), + mock.patch.object(upgrades, "contract_schema"), + ] + for p in patchers: + p.start() self.command_check = False self.command_expand = False self.command_migrate = False self.command_contract = False + def tearDown(self): + for p in self.patchers: + p.stop() + super().tearDown() + def _assert_correct_call(self, mocked_function): for func in [upgrades.offline_sync_database_to_version, upgrades.expand_schema, |