Skip to content

Commit a20800d

Browse files
committed
test_resource should not assume all attributes are available when they
are individually controlled by #ifdef statements in the extension code.
1 parent e38b054 commit a20800d

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

Lib/test/test_resource.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import contextlib
12
import sys
23
import os
34
import unittest
@@ -133,12 +134,9 @@ def test_pagesize(self):
133134

134135
@unittest.skipUnless(sys.platform == 'linux', 'test requires Linux')
135136
def test_linux_constants(self):
136-
self.assertIsInstance(resource.RLIMIT_MSGQUEUE, int)
137-
self.assertIsInstance(resource.RLIMIT_NICE, int)
138-
self.assertIsInstance(resource.RLIMIT_RTPRIO, int)
139-
self.assertIsInstance(resource.RLIMIT_RTTIME, int)
140-
self.assertIsInstance(resource.RLIMIT_SIGPENDING, int)
141-
137+
for attr in ['MSGQUEUE', 'NICE', 'RTPRIO', 'RTTIME', 'SIGPENDING']:
138+
with contextlib.suppress(AttributeError):
139+
self.assertIsInstance(getattr(resource, 'RLIMIT_' + attr), int)
142140

143141
@unittest.skipUnless(hasattr(resource, 'prlimit'), 'no prlimit')
144142
@support.requires_linux_version(2, 6, 36)

0 commit comments

Comments
 (0)