Skip to content

Commit f3ab006

Browse files
committed
tests: improve test_deprecated_mock
Use an inner test run to avoid the DeprecationWarning in the outer tests.
1 parent 648e399 commit f3ab006

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
@@ -129,14 +129,26 @@ def test_mock_patch_dict_resetall(mocker):
129129
assert x == {"new": 10}
130130

131131

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

141153

142154
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)