MCPcopy
hub / github.com/pytest-dev/pytest / test_importerror

Function test_importerror

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

Source from the content-addressed store, hash-verified

338
339
340def test_importerror(pytester: Pytester) -> None:
341 p = pytester.mkpydir("package")
342 p.joinpath("a.py").write_text(
343 textwrap.dedent(
344 """\
345 import doesnotexist
346
347 x = 1
348 """
349 ),
350 encoding="utf-8",
351 )
352 pytester.path.joinpath("test_importerror.py").write_text(
353 textwrap.dedent(
354 """\
355 def test_importerror(monkeypatch):
356 monkeypatch.setattr('package.a.x', 2)
357 """
358 ),
359 encoding="utf-8",
360 )
361 result = pytester.runpytest()
362 result.stdout.fnmatch_lines(
363 """
364 *import error in package.a: No module named 'doesnotexist'*
365 """
366 )
367
368
369class Sample:

Callers

nothing calls this directly

Calls 4

write_textMethod · 0.80
fnmatch_linesMethod · 0.80
mkpydirMethod · 0.45
runpytestMethod · 0.45

Tested by

no test coverage detected