Skip to content

Commit

Permalink
Testing exception on patch as context manager
Browse files Browse the repository at this point in the history
Adding a new test to confirm that patch raises an exception when used
as a context manager
  • Loading branch information
AlexGascon committed Oct 30, 2019
1 parent 6587f79 commit d3d10a5
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion tests/test_pytest_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ def test_get_random_number(mocker):
assert "RuntimeError" not in result.stderr.str()


def test_abort_context_manager(mocker):
def test_abort_patch_object_context_manager(mocker):
class A(object):
def doIt(self):
return False
Expand All @@ -740,3 +740,16 @@ def doIt(self):
)

assert str(excinfo.value) == expected_error_msg


def test_abort_patch_context_manager(mocker):
with pytest.raises(ValueError) as excinfo:
with mocker.patch("some_package"):
pass

expected_error_msg = (
"Using mocker in a with context is not supported. "
"https://github.com/pytest-dev/pytest-mock#note-about-usage-as-context-manager"
)

assert str(excinfo.value) == expected_error_msg

0 comments on commit d3d10a5

Please sign in to comment.