Skip to content

Commit

Permalink
Add test that checks that tests are run in gilless mode when using a …
Browse files Browse the repository at this point in the history
…freethreaded python

Issue #608
  • Loading branch information
ronaldoussoren committed Jul 14, 2024
1 parent 9a1ae8f commit 3ca2d58
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pyobjc-core/Lib/PyObjCTools/TestSupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,16 @@ def assertPickleRoundTrips(self, value):
self.assertEqual(clone, value)
self.assertIsInstance(clone, type(value))

def assertFreeThreadedIfConfigured(self):
"""
Assert that the process is running in free-threaded mode when
the interpreter was configured as such.
"""
if not _get_config_var("Py_GIL_DISABLED"):
return

self.assertFalse(_sys._is_gil_enabled(), "GIL is enabled")

def _validateCallableMetadata(
self, value, class_name=None, skip_simple_charptr_check=False
):
Expand Down Expand Up @@ -1393,6 +1403,10 @@ def assertCallableMetadataIsSane(
else:
continue

# Quick check that the GIL is actually disabled. Testing this here isn't
# ideal, but avoids changing all framework bindings.
self.assertFreeThreadedIfConfigured()

def __init__(self, methodName="runTest"):
super().__init__(methodName)

Expand Down
5 changes: 5 additions & 0 deletions pyobjc-core/PyObjCTest/test_regr.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,3 +680,8 @@ def __del__(self):
s = super(D, D())
del s
assert deleted


class TestFreeThreaded(TestCase):
def test_freethreaded_if_configured(self):
self.assertFreeThreadedIfConfigured()

0 comments on commit 3ca2d58

Please sign in to comment.