From e1047948bcb4b41a52be1326719d94fb88f2312e Mon Sep 17 00:00:00 2001 From: Pavel Koneski Date: Sun, 22 Dec 2024 18:21:00 -0800 Subject: [PATCH] Disable tests in Mono depending on gc.collect() (#1847) * Disable tests in Mono depending on gc.collect() * Skip more tests --- Tests/modules/type_related/test_ctypes.py | 5 +++- Tests/test_descr_stdlib.py | 10 +++++++- Tests/test_io_stdlib.py | 30 +++++++++++++++++++---- Tests/test_memoryio_stdlib.py | 8 +++++- Tests/test_namebinding.py | 4 ++- 5 files changed, 48 insertions(+), 9 deletions(-) diff --git a/Tests/modules/type_related/test_ctypes.py b/Tests/modules/type_related/test_ctypes.py index 3c390a1bf..f4c1fdf3e 100644 --- a/Tests/modules/type_related/test_ctypes.py +++ b/Tests/modules/type_related/test_ctypes.py @@ -12,7 +12,7 @@ import gc import unittest -from iptest import IronPythonTestCase, is_posix, is_cli, big, myint, run_test +from iptest import IronPythonTestCase, is_posix, is_cli, is_mono, big, myint, run_test class CTypesTest(IronPythonTestCase): export_error_msg = "Existing exports of data: object cannot be re-sized" if is_cli else "cannot resize an array that is exporting buffers" @@ -30,11 +30,14 @@ def test_from_array(self): self.assertRaisesMessage(BufferError, self.export_error_msg, arr.append, 100) self.assertRaisesMessage(BufferError, self.export_error_msg, arr.insert, 10, 100) + if is_mono: + with c: pass # gc.collect() in Mono may return before collection is finished del c gc.collect() arr.append(100) self.assertEqual(arr[-1], 100) + @unittest.skipIf(is_mono, "gc.collect() in Mono may return before collection is finished") def test_from_memoryview(self): arr = array('i', range(16)) with memoryview(arr) as mv: diff --git a/Tests/test_descr_stdlib.py b/Tests/test_descr_stdlib.py index fefcd40be..a0433a006 100644 --- a/Tests/test_descr_stdlib.py +++ b/Tests/test_descr_stdlib.py @@ -6,7 +6,7 @@ ## Run selected tests from test_descr from StdLib ## -from iptest import is_ironpython, generate_suite, run_test +from iptest import is_ironpython, is_mono, generate_suite, run_test import test.test_descr @@ -56,6 +56,14 @@ def load_tests(loader, standard_tests, pattern): skip_tests = [] + if is_mono: + skip_tests += [ + # On Mono, gc.collect() may return before collection is finished making some tests unreliable + test.test_descr.ClassPropertiesAndMethods('test_delete_hook'), + test.test_descr.ClassPropertiesAndMethods('test_subtype_resurrection'), + test.test_descr.ClassPropertiesAndMethods('test_weakrefs'), + ] + return generate_suite(tests, failing_tests, skip_tests) else: diff --git a/Tests/test_io_stdlib.py b/Tests/test_io_stdlib.py index f3e66d691..8a71c5e75 100644 --- a/Tests/test_io_stdlib.py +++ b/Tests/test_io_stdlib.py @@ -101,11 +101,6 @@ def load_tests(loader, standard_tests, pattern): test.test_io.PyMiscIOTest('test_warn_on_dealloc_fd'), # AssertionError: ResourceWarning not triggered ] - if is_mono: - failing_tests += [ - test.test_io.CBufferedRandomTest('test_destructor'), # IndexError: index out of range: 0 - ] - skip_tests = [ test.test_io.CBufferedWriterTest('test_override_destructor'), # StackOverflowException test.test_io.CBufferedRandomTest('test_override_destructor'), # StackOverflowException @@ -144,6 +139,31 @@ def load_tests(loader, standard_tests, pattern): test.test_io.PyMiscIOTest('test_attributes'), # AssertionError: 'wb+' != 'rb+' ] + if is_mono: + skip_tests += [ + # On Mono, gc.collect() may return before collection is finished making some tests unreliable + test.test_io.CBufferedRandomTest('test_destructor'), + test.test_io.CBufferedWriterTest('test_destructor'), + test.test_io.PyBufferedWriterTest('test_destructor'), + test.test_io.PyBufferedRandomTest('test_destructor'), + test.test_io.PyBufferedReaderTest('test_override_destructor'), + test.test_io.PyBufferedWriterTest('test_override_destructor'), + test.test_io.PyBufferedRandomTest('test_override_destructor'), + + test.test_io.CTextIOWrapperTest('test_destructor'), + test.test_io.CIOTest('test_IOBase_finalize'), + + test.test_io.PyTextIOWrapperTest('test_destructor'), + test.test_io.PyTextIOWrapperTest('test_override_destructor'), + test.test_io.PyIOTest('test_RawIOBase_destructor'), + test.test_io.PyIOTest('test_BufferedIOBase_destructor'), + test.test_io.PyIOTest('test_IOBase_destructor'), + test.test_io.PyIOTest('test_TextIOBase_destructor'), + + test.test_io.CMiscIOTest('test_blockingioerror'), + test.test_io.PyMiscIOTest('test_blockingioerror'), + ] + return generate_suite(tests, failing_tests, skip_tests) else: diff --git a/Tests/test_memoryio_stdlib.py b/Tests/test_memoryio_stdlib.py index 818257320..423c895ae 100644 --- a/Tests/test_memoryio_stdlib.py +++ b/Tests/test_memoryio_stdlib.py @@ -6,7 +6,7 @@ ## Run selected tests from test_memoryio from StdLib ## -from iptest import is_ironpython, generate_suite, run_test +from iptest import is_ironpython, is_mono, generate_suite, run_test import test.test_memoryio @@ -25,6 +25,12 @@ def load_tests(loader, standard_tests, pattern): test.test_memoryio.CStringIOTest('test_instance_dict_leak'), # https://github.com/IronLanguages/ironpython3/issues/1004 ] + if is_mono: + skip_tests += [ + # On Mono, gc.collect() may return before collection is finished making some tests unreliable + test.test_memoryio.PyBytesIOTest('test_getbuffer') + ] + return generate_suite(tests, failing_tests, skip_tests) else: diff --git a/Tests/test_namebinding.py b/Tests/test_namebinding.py index 1e2ffde9e..75919ff3d 100644 --- a/Tests/test_namebinding.py +++ b/Tests/test_namebinding.py @@ -3,8 +3,9 @@ # See the LICENSE file in the project root for more information. import sys +import unittest -from iptest import IronPythonTestCase, is_cli, path_modifier, run_test +from iptest import IronPythonTestCase, is_cli, is_mono, path_modifier, run_test glb = 0 res = '' @@ -312,6 +313,7 @@ def test_DelBuiltin(self): self.assertRaises(NameError, DoDelBuiltin) self.assertRaises(NameError, DoDelBuiltin) + @unittest.skipIf(is_mono, "TODO: figure out; the finalizer is called way after WaitForPendingFinalizers") def test_SimpleTest(self): """simple case""" global res