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