Skip to content

Commit 063b0e0

Browse files
dnicolodirgommers
authored andcommitted
TST: apply environment variable cleanup to all tests
This has no adverse consequence and makes it impossible to forget to add it to relevant tests, which is important because the tests are not commonly run with the environment variables set, making the failure hard to discover.
1 parent 1e69e7a commit 063b0e0

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

tests/conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,12 @@ def disable_pip_version_check():
183183
mpatch = pytest.MonkeyPatch()
184184
yield mpatch.setenv('PIP_DISABLE_PIP_VERSION_CHECK', '1')
185185
mpatch.undo()
186+
187+
188+
@pytest.fixture(autouse=True, scope='session')
189+
def cleanenv():
190+
# Cannot use the 'monkeypatch' fixture because of scope mismatch.
191+
mpatch = pytest.MonkeyPatch()
192+
# $MACOSX_DEPLOYMENT_TARGET affects the computation of the platform tag on macOS.
193+
yield mpatch.delenv('MACOSX_DEPLOYMENT_TARGET', raising=False)
194+
mpatch.undo()

tests/test_tags.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,7 @@ def get_abi3_suffix():
4040
ABI3SUFFIX = get_abi3_suffix()
4141

4242

43-
@pytest.fixture()
44-
def cleanenv(monkeypatch):
45-
# $MACOSX_DEPLOYMENT_TARGET affects the computation of the platform tag on macOS.
46-
monkeypatch.delenv('MACOSX_DEPLOYMENT_TARGET', raising=False)
47-
48-
49-
def test_wheel_tag(cleanenv):
43+
def test_wheel_tag():
5044
assert str(mesonpy._tags.Tag()) == f'{INTERPRETER}-{ABI}-{PLATFORM}'
5145
assert str(mesonpy._tags.Tag(abi='abi3')) == f'{INTERPRETER}-abi3-{PLATFORM}'
5246

@@ -118,14 +112,14 @@ def test_tag_purelib_wheel():
118112
assert str(builder.tag) == 'py3-none-any'
119113

120114

121-
def test_tag_platlib_wheel(cleanenv):
115+
def test_tag_platlib_wheel():
122116
builder = wheel_builder_test_factory({
123117
'platlib': [f'extension{SUFFIX}'],
124118
})
125119
assert str(builder.tag) == f'{INTERPRETER}-{ABI}-{PLATFORM}'
126120

127121

128-
def test_tag_stable_abi(cleanenv):
122+
def test_tag_stable_abi():
129123
builder = wheel_builder_test_factory({
130124
'platlib': [f'extension{ABI3SUFFIX}'],
131125
}, limited_api=True)
@@ -136,7 +130,7 @@ def test_tag_stable_abi(cleanenv):
136130

137131
@pytest.mark.xfail(sys.version_info < (3, 8) and sys.platform == 'win32', reason='Extension modules suffix without ABI tags')
138132
@pytest.mark.xfail('__pypy__' in sys.builtin_module_names, reason='PyPy does not support the stable ABI')
139-
def test_tag_mixed_abi(cleanenv):
133+
def test_tag_mixed_abi():
140134
builder = wheel_builder_test_factory({
141135
'platlib': [f'extension{ABI3SUFFIX}', f'another{SUFFIX}'],
142136
}, pure=False, limited_api=True)

0 commit comments

Comments
 (0)