Skip to content

Commit 2e27043

Browse files
committed
Use @unittest.skipUnless
1 parent 3941123 commit 2e27043

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

Lib/test/test_threading.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2103,17 +2103,9 @@ def test__all__(self):
21032103
support.check__all__(self, threading, ('threading', '_thread'),
21042104
extra=extra, not_exported=not_exported)
21052105

2106+
@unittest.skipUnless(hasattr(_thread, 'set_name'), "missing _thread.set_name")
2107+
@unittest.skipUnless(hasattr(_thread, '_get_name'), "missing _thread._get_name")
21062108
def test_set_name(self):
2107-
try:
2108-
get_name = _thread._get_name
2109-
_thread.set_name
2110-
except AttributeError:
2111-
self.skipTest("need thread._get_name() and thread.set_name()")
2112-
2113-
def work():
2114-
nonlocal work_name
2115-
work_name = get_name()
2116-
21172109
# set_name() limit in bytes
21182110
truncate = getattr(_thread, "_NAME_MAXLEN", None)
21192111
limit = truncate or 100
@@ -2144,6 +2136,10 @@ def work():
21442136
else:
21452137
encoding = sys.getfilesystemencoding()
21462138

2139+
def work():
2140+
nonlocal work_name
2141+
work_name = _thread._get_name()
2142+
21472143
for name in tests:
21482144
encoded = name.encode(encoding, "replace")
21492145
if truncate is not None:

0 commit comments

Comments
 (0)