Skip to content

Commit 0440115

Browse files
committed
Improve test_standalone_mock
This actually tests that the 'mock' module is being used when use_standalone_mock is true. It also skips the test if 'mock' is not installed. Close pytest-dev#276
1 parent 124c6f0 commit 0440115

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

tests/test_pytest_mock.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -707,10 +707,14 @@ def test_foo(mocker):
707707

708708
def test_standalone_mock(testdir: Any) -> None:
709709
"""Check that the "mock_use_standalone" is being used."""
710+
pytest.importorskip("mock")
711+
710712
testdir.makepyfile(
711713
"""
714+
import mock
715+
712716
def test_foo(mocker):
713-
pass
717+
assert mock.MagicMock is mocker.MagicMock
714718
"""
715719
)
716720
testdir.makeini(
@@ -720,8 +724,7 @@ def test_foo(mocker):
720724
"""
721725
)
722726
result = testdir.runpytest_subprocess()
723-
assert result.ret == 3
724-
result.stderr.fnmatch_lines(["*No module named 'mock'*"])
727+
assert result.ret == 0
725728

726729

727730
@pytest.mark.usefixtures("needs_assert_rewrite")

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ envlist = py{37,38,39,310}, norewrite
66
passenv = USER USERNAME
77
deps =
88
coverage
9+
mock
910
pytest-asyncio
1011
commands =
1112
coverage run --append --source={envsitepackagesdir}/pytest_mock -m pytest tests

0 commit comments

Comments
 (0)