Skip to content

Commit 51ab8f1

Browse files
committed
Avoid using (deprecated) 'json.__version__' in tests (#5194)
2 parents f9c37b2 + 09bafbc commit 51ab8f1

2 files changed

Lines changed: 21 additions & 16 deletions

File tree

newsfragments/5186.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Replaced deprecated ``json.__version__`` with fixture in tests.

setuptools/tests/test_setuptools.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,30 +77,34 @@ def testFindModule(self):
7777
f, _p, _i = dep.find_module('setuptools.tests')
7878
f.close()
7979

80-
@needs_bytecode
81-
def testModuleExtract(self):
82-
from json import __version__
80+
@pytest.fixture
81+
def sample_module(self, monkeypatch, tmp_path):
82+
monkeypatch.syspath_prepend(str(tmp_path))
83+
module = "mod_with_version"
84+
version = "2.0.9"
85+
file = tmp_path / f"{module}.py"
86+
file.write_text(f"__version__ = {version!r}", encoding="utf-8")
87+
return (module, version)
8388

84-
assert dep.get_module_constant('json', '__version__') == __version__
89+
@needs_bytecode
90+
def testModuleExtract(self, sample_module):
91+
(module, version) = sample_module
92+
assert dep.get_module_constant(module, '__version__') == version
8593
assert dep.get_module_constant('sys', 'version') == sys.version
86-
assert (
87-
dep.get_module_constant('setuptools.tests.test_setuptools', '__doc__')
88-
== __doc__
89-
)
94+
assert dep.get_module_constant(__name__, '__doc__') == __doc__
9095

9196
@needs_bytecode
92-
def testRequire(self):
93-
req = Require('Json', '1.0.3', 'json')
97+
def testRequire(self, sample_module):
98+
(module, version) = sample_module
99+
req = Require('GivenName', '1.0.3', module)
94100

95-
assert req.name == 'Json'
96-
assert req.module == 'json'
101+
assert req.name == 'GivenName'
102+
assert req.module == module
97103
assert req.requested_version == Version('1.0.3')
98104
assert req.attribute == '__version__'
99-
assert req.full_name() == 'Json-1.0.3'
100-
101-
from json import __version__
105+
assert req.full_name() == 'GivenName-1.0.3'
102106

103-
assert str(req.get_version()) == __version__
107+
assert str(req.get_version()) == version
104108
assert req.version_ok('1.0.9')
105109
assert not req.version_ok('0.9.1')
106110
assert not req.version_ok('unknown')

0 commit comments

Comments
 (0)