(pytester: Pytester)
| 311 | |
| 312 | |
| 313 | def 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 | |
| 340 | class Sample: |
nothing calls this directly
no test coverage detected