Skip to content

Commit 32e5fea

Browse files
committed
Rely on monkeysession to monkeypatch.
1 parent 5f79f22 commit 32e5fea

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

conftest.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def disable_macos_customization(monkeypatch):
165165

166166

167167
@pytest.fixture(autouse=True, scope="session")
168-
def monkey_patch_get_default_compiler():
168+
def monkey_patch_get_default_compiler(monkeysession):
169169
"""
170170
Monkey patch distutils get_default_compiler to allow overriding the
171171
default compiler. Mainly to test mingw32 with a MSVC Python.
@@ -174,14 +174,10 @@ def monkey_patch_get_default_compiler():
174174

175175
default_compiler = os.environ.get("DISTUTILS_TEST_DEFAULT_COMPILER")
176176

177-
if default_compiler is not None:
177+
if default_compiler is None:
178+
return
178179

179-
def patched_get_default_compiler(*args, **kwargs):
180-
return default_compiler
180+
def patched_getter(*args, **kwargs):
181+
return default_compiler
181182

182-
original = ccompiler.get_default_compiler
183-
ccompiler.get_default_compiler = patched_get_default_compiler
184-
yield
185-
ccompiler.get_default_compiler = original
186-
else:
187-
yield
183+
monkeysession.setattr(ccompiler, 'get_default_compiler', patched_getter)

0 commit comments

Comments
 (0)