MCPcopy Create free account
hub / github.com/pytest-dev/pytest / test_mock

Method test_mock

testing/python/integration.py:220–251  ·  view source on GitHub ↗
(self, pytester: Pytester)

Source from the content-addressed store, hash-verified

218 reprec.assertoutcome(passed=1)
219
220 def test_mock(self, pytester: Pytester) -> None:
221 pytest.importorskip("mock", "1.0.1")
222 pytester.makepyfile(
223 """
224 import os
225 import unittest
226 import mock
227
228 class T(unittest.TestCase):
229 @mock.patch("os.path.abspath")
230 def test_hello(self, abspath):
231 os.path.abspath("hello")
232 abspath.assert_any_call("hello")
233 def mock_basename(path):
234 return "mock_basename"
235 @mock.patch("os.path.abspath")
236 @mock.patch("os.path.normpath")
237 @mock.patch("os.path.basename", new=mock_basename)
238 def test_someting(normpath, abspath, tmp_path):
239 abspath.return_value = "this"
240 os.path.normpath(os.path.abspath("hello"))
241 normpath.assert_any_call("this")
242 assert os.path.basename("123") == "mock_basename"
243 """
244 )
245 reprec = pytester.inline_run()
246 reprec.assertoutcome(passed=2)
247 calls = reprec.getcalls("pytest_runtest_logreport")
248 funcnames = [
249 call.report.location[2] for call in calls if call.report.when == "call"
250 ]
251 assert funcnames == ["T.test_hello", "test_someting"]
252
253 def test_mock_sorting(self, pytester: Pytester) -> None:
254 pytest.importorskip("mock", "1.0.1")

Callers

nothing calls this directly

Calls 4

assertoutcomeMethod · 0.80
getcallsMethod · 0.80
makepyfileMethod · 0.45
inline_runMethod · 0.45

Tested by

no test coverage detected