From 7717023bff93d95e3481f4de8244691d1f6039bc Mon Sep 17 00:00:00 2001 From: stakeswky Date: Mon, 23 Feb 2026 11:45:04 +0800 Subject: [PATCH] Replace deprecated json.__version__ with test fixture module in tests json.__version__ was deprecated in Python 3.15 (slated for removal in 3.20) and is now provided via module __getattr__ rather than as a bytecode constant. This causes TestDepends.testModuleExtract and TestDepends.testRequire to fail because get_module_constant cannot extract attributes set through __getattr__. Replace the json module references with the existing test fixture module (setuptools.tests.mod_with_constant), adding a __version__ constant to it. This makes the tests independent of stdlib deprecation cycles while still exercising the same code paths. Fixes #5186 --- setuptools/tests/mod_with_constant.py | 1 + setuptools/tests/test_setuptools.py | 24 +++++++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/setuptools/tests/mod_with_constant.py b/setuptools/tests/mod_with_constant.py index ef755dd1c7..48aa636e66 100644 --- a/setuptools/tests/mod_with_constant.py +++ b/setuptools/tests/mod_with_constant.py @@ -1 +1,2 @@ value = 'three, sir!' +__version__ = '1.0.3' diff --git a/setuptools/tests/test_setuptools.py b/setuptools/tests/test_setuptools.py index 1d56e1a8a4..1387934ccc 100644 --- a/setuptools/tests/test_setuptools.py +++ b/setuptools/tests/test_setuptools.py @@ -79,9 +79,16 @@ def testFindModule(self): @needs_bytecode def testModuleExtract(self): - from json import __version__ + # Use a test fixture module instead of json, whose __version__ was + # deprecated in Python 3.15 and moved behind __getattr__ (gh-5186). + from setuptools.tests.mod_with_constant import __version__ - assert dep.get_module_constant('json', '__version__') == __version__ + assert ( + dep.get_module_constant( + 'setuptools.tests.mod_with_constant', '__version__' + ) + == __version__ + ) assert dep.get_module_constant('sys', 'version') == sys.version assert ( dep.get_module_constant('setuptools.tests.test_setuptools', '__doc__') @@ -90,15 +97,18 @@ def testModuleExtract(self): @needs_bytecode def testRequire(self): - req = Require('Json', '1.0.3', 'json') + # Use a test fixture module instead of json, whose __version__ was + # deprecated in Python 3.15 and moved behind __getattr__ (gh-5186). + mod_name = 'setuptools.tests.mod_with_constant' + req = Require('ModWithConstant', '1.0.3', mod_name) - assert req.name == 'Json' - assert req.module == 'json' + assert req.name == 'ModWithConstant' + assert req.module == mod_name assert req.requested_version == Version('1.0.3') assert req.attribute == '__version__' - assert req.full_name() == 'Json-1.0.3' + assert req.full_name() == 'ModWithConstant-1.0.3' - from json import __version__ + from setuptools.tests.mod_with_constant import __version__ assert str(req.get_version()) == __version__ assert req.version_ok('1.0.9')