Skip to content

Instantly share code, notes, and snippets.

@hpk42
Created March 26, 2014 15:53
Show Gist options
  • Save hpk42/9786568 to your computer and use it in GitHub Desktop.
Save hpk42/9786568 to your computer and use it in GitHub Desktop.
def test_monkeypatch_context_processor_with_exception(monkeypatch):
monkeypatch = MonkeyPatch()
class TerribleException(Exception):
pass
@staticmethod
def _func():
raise TerribleException('terrible!')
mp.setattr(SampleNew, 'hello', _func)
with pytest.raises(TerribleException):
assert SampleNew.hello()
monkeypatch.undo()
assert SampleNew.hello() is True
@hpk42
Copy link
Author

hpk42 commented Mar 26, 2014

def test_monkeypatch_context_processor_with_exception(monkeypatch):
class TerribleException(Exception):
pass

@staticmethod
def _func():
    raise TerribleException('terrible!')

monkeypatch.setattr(SampleNew, 'hello', _func)
with pytest.raises(TerribleException):
    assert SampleNew.hello()
monkeypatch.undo()
assert SampleNew.hello() is True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment