Skip to content

Commit

Permalink
Improve test_standalone_mock
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nicoddemus committed Jan 28, 2022
1 parent 124c6f0 commit 0440115
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tests/test_pytest_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,10 +707,14 @@ def test_foo(mocker):

def test_standalone_mock(testdir: Any) -> None:
"""Check that the "mock_use_standalone" is being used."""
pytest.importorskip("mock")

testdir.makepyfile(
"""
import mock
def test_foo(mocker):
pass
assert mock.MagicMock is mocker.MagicMock
"""
)
testdir.makeini(
Expand All @@ -720,8 +724,7 @@ def test_foo(mocker):
"""
)
result = testdir.runpytest_subprocess()
assert result.ret == 3
result.stderr.fnmatch_lines(["*No module named 'mock'*"])
assert result.ret == 0


@pytest.mark.usefixtures("needs_assert_rewrite")
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ envlist = py{37,38,39,310}, norewrite
passenv = USER USERNAME
deps =
coverage
mock
pytest-asyncio
commands =
coverage run --append --source={envsitepackagesdir}/pytest_mock -m pytest tests
Expand Down

0 comments on commit 0440115

Please sign in to comment.