Skip to content

Commit a5c2b7a

Browse files
committed
fix warnings found in test_importlib.test_windows
1 parent ec6a368 commit a5c2b7a

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

Lib/test/test_importlib/test_windows.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,46 @@ class WindowsRegistryFinderTests:
9191
test_module = "spamham{}".format(os.getpid())
9292

9393
def test_find_spec_missing(self):
94-
spec = self.machinery.WindowsRegistryFinder.find_spec('spam')
94+
with self.assertWarnsRegex(
95+
DeprecationWarning,
96+
r"importlib\.machinery\.WindowsRegistryFinder is deprecated; "
97+
r"use site configuration instead\. Future versions of Python may "
98+
r"not enable this finder by default\."
99+
):
100+
spec = self.machinery.WindowsRegistryFinder.find_spec('spam')
95101
self.assertIsNone(spec)
96102

97103
def test_module_found(self):
98104
with setup_module(self.machinery, self.test_module):
99-
spec = self.machinery.WindowsRegistryFinder.find_spec(self.test_module)
105+
with self.assertWarnsRegex(
106+
DeprecationWarning,
107+
r"importlib\.machinery\.WindowsRegistryFinder is deprecated; "
108+
r"use site configuration instead\. Future versions of Python may "
109+
r"not enable this finder by default\."
110+
):
111+
spec = self.machinery.WindowsRegistryFinder.find_spec(self.test_module)
100112
self.assertIsNotNone(spec)
101113

102114
def test_module_not_found(self):
103115
with setup_module(self.machinery, self.test_module, path="."):
104-
spec = self.machinery.WindowsRegistryFinder.find_spec(self.test_module)
116+
with self.assertWarnsRegex(
117+
DeprecationWarning,
118+
r"importlib\.machinery\.WindowsRegistryFinder is deprecated; "
119+
r"use site configuration instead\. Future versions of Python may "
120+
r"not enable this finder by default\."
121+
):
122+
spec = self.machinery.WindowsRegistryFinder.find_spec(self.test_module)
105123
self.assertIsNone(spec)
106124

107125
def test_raises_deprecation_warning(self):
108126
# WindowsRegistryFinder is not meant to be instantiated, so the
109127
# deprecation warning is raised in the 'find_spec' method instead.
110-
with self.assertWarns(DeprecationWarning):
128+
with self.assertWarnsRegex(
129+
DeprecationWarning,
130+
r"importlib\.machinery\.WindowsRegistryFinder is deprecated; "
131+
r"use site configuration instead\. Future versions of Python may "
132+
r"not enable this finder by default\."
133+
):
111134
self.machinery.WindowsRegistryFinder.find_spec('spam')
112135

113136
(Frozen_WindowsRegistryFinderTests,

0 commit comments

Comments
 (0)