Skip to content

Commit 0fded69

Browse files
committed
replace unittest.mock._get_target with mock one
Use the original importer for mock. Otherwise, the unit tests that use importlib with context are not running in an isolated manner, leading to various transient failures if `stestr` is not run with the `--isolated` flag. The unittest.mock._get_target has been changed in Python 3.11, by commit: python/cpython@ab7fcc8 This change is needed to add support for Python 3.11 and Python 3.12 unit testing. Change-Id: Ic73f5280116673f771f5460cdfd3702f5fbe16b5
1 parent 36ed936 commit 0fded69

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

cloudbaseinit/tests/__init__.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2023 Cloudbase Solutions Srl
2+
#
3+
# All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License. You may obtain
7+
# a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
# License for the specific language governing permissions and limitations
15+
# under the License.
16+
17+
from unittest import mock
18+
19+
from mock import mock as mock_base
20+
21+
# Note(avladu): use the original mock._get_target for unittest.mock.
22+
# Otherwise, the unit tests that use importlib with context are not
23+
# running in an isolated manner, leading to various transient failures.
24+
mock._get_target = mock_base._get_target

0 commit comments

Comments
 (0)