Skip to content

Commit f294d52

Browse files
authored
tests: do not reload the tags module (#1152)
Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
1 parent 2c6c7df commit f294d52

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

src/packaging/tags.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,13 @@ def __dir__() -> list[str]:
7070
}
7171

7272

73-
_32_BIT_INTERPRETER = struct.calcsize("P") == 4
73+
# This function can be unit tested without reloading the module
74+
# (Unlike _32_BIT_INTERPRETER)
75+
def _compute_32_bit_interpreter() -> bool:
76+
return struct.calcsize("P") == 4
77+
78+
79+
_32_BIT_INTERPRETER = _compute_32_bit_interpreter()
7480

7581

7682
class Tag:

tests/test_tags.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import ctypes
1212
except ImportError:
1313
ctypes = None # type: ignore[assignment]
14-
import importlib
1514
import os
1615
import pathlib
1716
import pickle
@@ -1806,9 +1805,6 @@ def test_pyemscripten(
18061805

18071806

18081807
class TestBitness:
1809-
def teardown_method(self) -> None:
1810-
importlib.reload(tags)
1811-
18121808
@pytest.mark.parametrize(
18131809
("maxsize", "sizeof_voidp", "expected"),
18141810
[
@@ -1833,8 +1829,7 @@ def _calcsize(fmt: str) -> int:
18331829

18341830
monkeypatch.setattr(sys, "maxsize", maxsize)
18351831
monkeypatch.setattr(struct, "calcsize", _calcsize)
1836-
importlib.reload(tags)
1837-
assert expected == tags._32_BIT_INTERPRETER
1832+
assert expected == tags._compute_32_bit_interpreter()
18381833

18391834

18401835
def test_pickle() -> None:

0 commit comments

Comments
 (0)