Is it safe to override the existing monkeypatch
fixture?
#10317
-
Is it safe to override the existing # tests/conftest.py
import pytest
class ExtendedMonkeyPatch(pytest.MonkeyPatch): # type: ignore
def setenvs(self, envs, prepend=None):
for name, value in envs.items():
self.setenv(name, value, prepend)
def delenvs(self, names, raising=True):
for name in names:
self.delenv(name, raising)
@pytest.fixture
def monkeypatch():
"""
Overrides the default monkeypatch fixture to add `setenvs` and `delenvs` methods.
"""
with ExtendedMonkeyPatch().context() as mp:
yield mp |
Beta Was this translation helpful? Give feedback.
Answered by
RonnyPfannschmidt
Sep 26, 2022
Replies: 1 comment 1 reply
-
With the code as proposed here it seems safe enough. Generally it's not advised to override the built-in fixtures. In this particular case it's a strict extension for convenience, so it's admissible. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
harupy
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With the code as proposed here it seems safe enough.
Generally it's not advised to override the built-in fixtures.
In this particular case it's a strict extension for convenience, so it's admissible.