Skip to content

Instantly share code, notes, and snippets.

@hpk42
Created March 26, 2014 15:55
Show Gist options
  • Save hpk42/9786612 to your computer and use it in GitHub Desktop.
Save hpk42/9786612 to your computer and use it in GitHub Desktop.
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