From c66f5afa1ecf2d16cb61694075038794301eb51a Mon Sep 17 00:00:00 2001 From: Kumar Aditya Date: Sat, 7 Jun 2025 22:39:36 +0530 Subject: [PATCH 1/2] mark tests as thread unsafe --- src/c/test_c.py | 7 ++++--- testing/cffi1/test_ffi_obj.py | 1 + testing/cffi1/test_pkgconfig.py | 3 ++- testing/cffi1/test_re_python.py | 3 +++ testing/embedding/test_basic.py | 2 +- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/c/test_c.py b/src/c/test_c.py index ad691e4e..f45893c3 100644 --- a/src/c/test_c.py +++ b/src/c/test_c.py @@ -3288,6 +3288,7 @@ class mylist(list): pytest.raises(RuntimeError, from_handle, cast(BCharP, 0)) def test_new_handle_cycle(): + import gc import _weakref BVoidP = new_pointer_type(new_void_type()) class A(object): @@ -3296,9 +3297,9 @@ class A(object): o.cycle = newp_handle(BVoidP, o) wr = _weakref.ref(o) del o - for i in range(3): - if wr() is not None: - import gc; gc.collect() + # free-threading requires more iterations to clear weakref + while wr() is not None: + gc.collect() assert wr() is None def _test_bitfield_details(flag): diff --git a/testing/cffi1/test_ffi_obj.py b/testing/cffi1/test_ffi_obj.py index 7a7fc4f2..60fb50f8 100644 --- a/testing/cffi1/test_ffi_obj.py +++ b/testing/cffi1/test_ffi_obj.py @@ -32,6 +32,7 @@ def test_ffi_cache_type(): assert ffi.typeof("int[][10]") is ffi.typeof("int[][10]") assert ffi.typeof("int(*)()") is ffi.typeof("int(*)()") +@pytest.mark.thread_unsafe def test_ffi_type_not_immortal(): import weakref, gc ffi = _cffi1_backend.FFI() diff --git a/testing/cffi1/test_pkgconfig.py b/testing/cffi1/test_pkgconfig.py index 40e00595..5f4c2ac8 100644 --- a/testing/cffi1/test_pkgconfig.py +++ b/testing/cffi1/test_pkgconfig.py @@ -25,7 +25,7 @@ def test_merge_flags(): "bar" : ["b", "a", "z"], "foo" : []} - +@pytest.mark.thread_unsafe def test_pkgconfig(): assert pkgconfig.flags_from_pkgconfig([]) == {} @@ -56,6 +56,7 @@ def communicate(self): self.returncode = rc return bout, berr +@pytest.mark.thread_unsafe def test_call(): saved = pkgconfig.subprocess try: diff --git a/testing/cffi1/test_re_python.py b/testing/cffi1/test_re_python.py index 57e29a8c..56713af5 100644 --- a/testing/cffi1/test_re_python.py +++ b/testing/cffi1/test_re_python.py @@ -186,6 +186,7 @@ def test_include_1(): p = ffi.new("bar_t *", [5, b"foobar"]) assert p.a[4] == ord('a') +@pytest.mark.thread_unsafe def test_global_var(): from re_python_pysrc import ffi lib = ffi.dlopen(extmod) @@ -238,6 +239,7 @@ def test_partial_enum(): pytest.raises(VerificationMissing, ffi.emit_python_code, str(tmpdir.join('test_partial_enum.py'))) +@pytest.mark.thread_unsafe def test_anonymous_union_inside_struct(): # based on issue #357 from re_python_pysrc import ffi @@ -262,6 +264,7 @@ def test_anonymous_union_inside_struct(): assert ffi.offsetof("struct NVGcolor", "b") == FLOAT * 2 assert ffi.offsetof("struct NVGcolor", "a") == FLOAT * 3 +@pytest.mark.thread_unsafe def test_selfref(): # based on issue #429 from re_python_pysrc import ffi diff --git a/testing/embedding/test_basic.py b/testing/embedding/test_basic.py index 5ef399b9..f66aa889 100644 --- a/testing/embedding/test_basic.py +++ b/testing/embedding/test_basic.py @@ -39,7 +39,7 @@ def copy_away_env(): except NameError: org_env = os.environ.copy() - +@pytest.mark.thread_unsafe class EmbeddingTests: _compiled_modules = {} From 35bea7e3759ebaa38994d95ce3f736eefd49bc15 Mon Sep 17 00:00:00 2001 From: Kumar Aditya Date: Sun, 8 Jun 2025 00:02:51 +0530 Subject: [PATCH 2/2] mark TestZIntegration as thread unsafe --- testing/cffi0/test_zintegration.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/testing/cffi0/test_zintegration.py b/testing/cffi0/test_zintegration.py index 7612ba00..35083325 100644 --- a/testing/cffi0/test_zintegration.py +++ b/testing/cffi0/test_zintegration.py @@ -18,7 +18,7 @@ def create_venv(name): # FUTURE: we should probably update this to use venv for at least more modern Pythons, and # install setuptools/pip/etc explicitly for the tests that require them (as venv has stopped including # setuptools and wheel by default for newer versions). - subprocess.check_call(['virtualenv', + subprocess.check_call(['virtualenv', #'--never-download', <= could be added, but causes failures # in random cases on random machines '-p', os.path.abspath(sys.executable), @@ -119,6 +119,7 @@ def run_setup_and_program(dirname, python_snippet): assert not os.path.exists(str(SNIPPET_DIR.join(dirname, 'lextab.py'))) assert not os.path.exists(str(SNIPPET_DIR.join(dirname, 'yacctab.py'))) +@pytest.mark.thread_unsafe class TestZIntegration(object): def teardown_class(self): if udir.isdir():