Skip to content

Commit 94f3181

Browse files
osfricklertbreeds
authored andcommitted
Fix pkg_resources exception handling for py312
The exception that is generated on parsing errors has changed in Python 3.12, match on the generic ValueError instead. Also switch to using the simpler assertRaises() call instead of explicitly dealing with exceptions. Note that this is just a temporary workaround, we should really move away for using pkg_resources completely, see [0] and [1]. [0] https://setuptools.pypa.io/en/latest/pkg_resources.html [1] https://importlib-resources.readthedocs.io/en/latest/migration.html Change-Id: I20422194f6fc6d1c4ba49da754a2c3aab99a282c (cherry picked from commit c7d9856)
1 parent 275c459 commit 94f3181

File tree

1 file changed

+3
-16
lines changed

1 file changed

+3
-16
lines changed

openstack_requirements/tests/test_requirement.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
import textwrap
1414

15-
import pkg_resources
16-
import pkg_resources.extern.packaging.requirements as pkg_resources_reqs
1715
import testscenarios
1816
import testtools
1917

@@ -107,13 +105,7 @@ class TestParseRequirementFailures(testtools.TestCase):
107105
('-f', dict(line='-f http://tarballs.openstack.org/'))]
108106

109107
def test_does_not_parse(self):
110-
try:
111-
requirement.parse_line(self.line)
112-
except (pkg_resources.RequirementParseError,
113-
pkg_resources_reqs.InvalidRequirement):
114-
pass
115-
else:
116-
self.fail('No exception triggered')
108+
self.assertRaises(ValueError, requirement.parse_line, self.line)
117109

118110

119111
class TestToContent(testtools.TestCase):
@@ -153,13 +145,8 @@ def test_urls(self):
153145
self.assertEqual(reqs, [(req, line)])
154146

155147
def test_not_urls(self):
156-
try:
157-
list(requirement.to_reqs('file:///foo#egg=foo'))
158-
except (pkg_resources.RequirementParseError,
159-
pkg_resources_reqs.InvalidRequirement):
160-
pass
161-
else:
162-
self.fail('No exception triggered')
148+
self.assertRaises(
149+
ValueError, list, requirement.to_reqs('file:///foo#egg=foo'))
163150

164151
def test_multiline(self):
165152
content = textwrap.dedent("""\

0 commit comments

Comments
 (0)