diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py index a7da8d237a..780443844f 100644 --- a/psutil/tests/__init__.py +++ b/psutil/tests/__init__.py @@ -87,16 +87,17 @@ "HAS_IONICE", "HAS_MEMORY_MAPS", "HAS_PROC_CPU_NUM", "HAS_RLIMIT", "HAS_SENSORS_BATTERY", "HAS_BATTERY", "HAS_SENSORS_FANS", "HAS_SENSORS_TEMPERATURES", "HAS_MEMORY_FULL_INFO", "MACOS_11PLUS", - "MACOS_12PLUS", + "MACOS_12PLUS", "MACOS_ARM64", # subprocesses 'pyrun', 'terminate', 'reap_children', 'spawn_testproc', 'spawn_zombie', 'spawn_children_pair', # threads 'ThreadTask' # test utils - 'unittest', 'skip_on_access_denied', 'skip_on_not_implemented', - 'retry_on_failure', 'TestMemoryLeak', 'PsutilTestCase', - 'process_namespace', 'system_namespace', 'print_sysinfo', + 'expectedFailureIf', 'unittest', 'skip_on_access_denied', + 'skip_on_not_implemented', 'retry_on_failure', 'TestMemoryLeak', + 'PsutilTestCase', 'process_namespace', 'system_namespace', + 'print_sysinfo', # install utils 'install_pip', 'install_test_deps', # fs utils @@ -130,6 +131,7 @@ CI_TESTING = APPVEYOR or GITHUB_ACTIONS # are we a 64 bit process? IS_64BIT = sys.maxsize > 2 ** 32 +MACOS_ARM64 = MACOS and platform.machine() == 'arm64' @memoize @@ -901,6 +903,18 @@ def subTest(self, *args, **kw): unittest.TestCase = TestCase +def expectedFailureIf(condition): + """The test is marked as an expectedFailure if the condition is + satisfied. + """ + def wrapper(func): + if condition: + return unittest.expectedFailure(func) + else: + return func + return wrapper + + class PsutilTestCase(TestCase): """Test class providing auto-cleanup wrappers on top of process test utilities. diff --git a/psutil/tests/test_contracts.py b/psutil/tests/test_contracts.py index d376a33853..f3e9e730db 100755 --- a/psutil/tests/test_contracts.py +++ b/psutil/tests/test_contracts.py @@ -42,6 +42,7 @@ from psutil.tests import HAS_NET_IO_COUNTERS from psutil.tests import HAS_SENSORS_FANS from psutil.tests import HAS_SENSORS_TEMPERATURES +from psutil.tests import MACOS_ARM64 from psutil.tests import PYPY from psutil.tests import SKIP_SYSCONS from psutil.tests import VALID_PROC_STATUSES @@ -49,6 +50,7 @@ from psutil.tests import check_connection_ntuple from psutil.tests import create_sockets from psutil.tests import enum +from psutil.tests import expectedFailureIf from psutil.tests import is_namedtuple from psutil.tests import kernel_version from psutil.tests import process_namespace @@ -236,6 +238,7 @@ def test_cpu_count(self): self.assertIsInstance(psutil.cpu_count(), int) @unittest.skipIf(not HAS_CPU_FREQ, "not supported") + @expectedFailureIf(MACOS_ARM64) # macOS arm64 not supported: issue #1892 def test_cpu_freq(self): if psutil.cpu_freq() is None: raise self.skipTest("cpu_freq() returns None") diff --git a/psutil/tests/test_memleaks.py b/psutil/tests/test_memleaks.py index e507e837c2..d8f910efed 100755 --- a/psutil/tests/test_memleaks.py +++ b/psutil/tests/test_memleaks.py @@ -43,8 +43,10 @@ from psutil.tests import HAS_SENSORS_BATTERY from psutil.tests import HAS_SENSORS_FANS from psutil.tests import HAS_SENSORS_TEMPERATURES +from psutil.tests import MACOS_ARM64 from psutil.tests import TestMemoryLeak from psutil.tests import create_sockets +from psutil.tests import expectedFailureIf from psutil.tests import get_testfn from psutil.tests import process_namespace from psutil.tests import skip_on_access_denied @@ -365,6 +367,7 @@ def test_cpu_stats(self): @fewtimes_if_linux() @unittest.skipIf(not HAS_CPU_FREQ, "not supported") + @expectedFailureIf(MACOS_ARM64) # macOS arm64 not supported: issue #1892 def test_cpu_freq(self): self.execute(psutil.cpu_freq) diff --git a/psutil/tests/test_osx.py b/psutil/tests/test_osx.py index d0f588ad6f..2af958a825 100755 --- a/psutil/tests/test_osx.py +++ b/psutil/tests/test_osx.py @@ -14,9 +14,11 @@ from psutil import MACOS from psutil import POSIX from psutil.tests import HAS_BATTERY +from psutil.tests import MACOS_ARM64 from psutil.tests import TOLERANCE_DISK_USAGE from psutil.tests import TOLERANCE_SYS_MEM from psutil.tests import PsutilTestCase +from psutil.tests import expectedFailureIf from psutil.tests import retry_on_failure from psutil.tests import sh from psutil.tests import spawn_testproc @@ -144,6 +146,7 @@ def test_cpu_count_cores(self): num = sysctl("sysctl hw.physicalcpu") self.assertEqual(num, psutil.cpu_count(logical=False)) + @expectedFailureIf(MACOS_ARM64) # macOS arm64 not supported: issue #1892 def test_cpu_freq(self): freq = psutil.cpu_freq() self.assertEqual( diff --git a/psutil/tests/test_system.py b/psutil/tests/test_system.py index 753249bc33..721a0e8a62 100755 --- a/psutil/tests/test_system.py +++ b/psutil/tests/test_system.py @@ -45,11 +45,13 @@ from psutil.tests import HAS_SENSORS_TEMPERATURES from psutil.tests import IS_64BIT from psutil.tests import MACOS_12PLUS +from psutil.tests import MACOS_ARM64 from psutil.tests import PYPY from psutil.tests import UNICODE_SUFFIX from psutil.tests import PsutilTestCase from psutil.tests import check_net_address from psutil.tests import enum +from psutil.tests import expectedFailureIf from psutil.tests import mock from psutil.tests import retry_on_failure @@ -512,6 +514,7 @@ def test_cpu_stats(self): self.assertGreater(value, 0) @unittest.skipIf(not HAS_CPU_FREQ, "not supported") + @expectedFailureIf(MACOS_ARM64) # macOS arm64 not supported: issue #1892 def test_cpu_freq(self): def check_ls(ls): for nt in ls: