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

Function test_importerror

testing/test_monkeypatch.py:313–337  ·  view source on GitHub ↗
(pytester: Pytester)

Source from the content-addressed store, hash-verified

311
312
313def test_importerror(pytester: Pytester) -> None:
314 p = pytester.mkpydir("package")
315 p.joinpath("a.py").write_text(
316 textwrap.dedent(
317 """\
318 import doesnotexist
319
320 x = 1
321 """
322 )
323 )
324 pytester.path.joinpath("test_importerror.py").write_text(
325 textwrap.dedent(
326 """\
327 def test_importerror(monkeypatch):
328 monkeypatch.setattr('package.a.x', 2)
329 """
330 )
331 )
332 result = pytester.runpytest()
333 result.stdout.fnmatch_lines(
334 """
335 *import error in package.a: No module named 'doesnotexist'*
336 """
337 )
338
339
340class Sample:

Callers

nothing calls this directly

Calls 3

fnmatch_linesMethod · 0.80
mkpydirMethod · 0.45
runpytestMethod · 0.45

Tested by

no test coverage detected