Skip to content

Commit 7222f0c

Browse files
authored
Merge pull request #141 from blueyed/improve-test_deprecated_mock
tests: improve test_deprecated_mock
2 parents c389395 + f3ab006 commit 7222f0c

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

test_pytest_mock.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,26 @@ def test_mock_patch_dict_resetall(mocker):
132132
assert x == {"new": 10}
133133

134134

135-
def test_deprecated_mock(mock, tmpdir):
135+
def test_deprecated_mock(testdir):
136136
"""
137137
Use backward-compatibility-only mock fixture to ensure complete coverage.
138138
"""
139-
mock.patch("os.listdir", return_value=["mocked"])
140-
assert os.listdir(str(tmpdir)) == ["mocked"]
141-
mock.stopall()
142-
assert os.listdir(str(tmpdir)) == []
139+
p1 = testdir.makepyfile(
140+
"""
141+
import os
142+
143+
def test(mock, tmpdir):
144+
mock.patch("os.listdir", return_value=["mocked"])
145+
assert os.listdir(str(tmpdir)) == ["mocked"]
146+
mock.stopall()
147+
assert os.listdir(str(tmpdir)) == []
148+
"""
149+
)
150+
result = testdir.runpytest(str(p1))
151+
result.stdout.fnmatch_lines(
152+
['*DeprecationWarning: "mock" fixture has been deprecated, use "mocker"*']
153+
)
154+
assert result.ret == 0
143155

144156

145157
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)