4
4
5
5
import mypy .version
6
6
from packaging .version import Version
7
- import pexpect
8
7
import pytest
9
8
10
9
import pytest_mypy
11
10
12
11
13
12
MYPY_VERSION = Version (mypy .version .__version__ )
14
- PYTEST_VERSION = Version (pytest .__version__ )
15
13
PYTHON_VERSION = Version (
16
14
"." .join (
17
15
str (token )
@@ -325,14 +323,7 @@ def pytest_configure(config):
325
323
@pytest .mark .parametrize (
326
324
"module_name" ,
327
325
[
328
- pytest .param (
329
- "__init__" ,
330
- marks = pytest .mark .xfail (
331
- Version ("3.10" ) <= PYTEST_VERSION < Version ("6.2" ),
332
- raises = AssertionError ,
333
- reason = "https://github.com/pytest-dev/pytest/issues/8016" ,
334
- ),
335
- ),
326
+ "__init__" ,
336
327
"good" ,
337
328
],
338
329
)
@@ -464,14 +455,6 @@ def pyfunc(x: int) -> str:
464
455
expect_timeout = 60.0 ,
465
456
)
466
457
467
- num_tests = 2
468
- if module_name == "__init__" and Version ("3.10" ) <= PYTEST_VERSION < Version ("6.2" ):
469
- # https://github.com/pytest-dev/pytest/issues/8016
470
- # Pytest had a bug where it assumed only a Package would have a basename of
471
- # __init__.py. In this test, Pytest mistakes MypyFile for a Package and
472
- # returns after collecting only one object (the MypyFileItem).
473
- num_tests = 1
474
-
475
458
def _expect_session ():
476
459
child .expect ("==== test session starts ====" )
477
460
@@ -480,11 +463,9 @@ def _expect_failure():
480
463
child .expect ("==== FAILURES ====" )
481
464
child .expect (pyfile .basename + " ____" )
482
465
child .expect ("2: error: Incompatible return value" )
483
- # if num_tests == 2:
484
- # # These only show with mypy>=0.730:
485
- # child.expect("==== mypy ====")
486
- # child.expect("Found 1 error in 1 file (checked 1 source file)")
487
- child .expect (str (num_tests ) + " failed" )
466
+ child .expect ("==== mypy ====" )
467
+ child .expect ("Found 1 error in 1 file (checked 1 source file)" )
468
+ child .expect ("2 failed" )
488
469
child .expect ("#### LOOPONFAILING ####" )
489
470
_expect_waiting ()
490
471
@@ -503,29 +484,9 @@ def _expect_changed():
503
484
def _expect_success ():
504
485
for _ in range (2 ):
505
486
_expect_session ()
506
- # if num_tests == 2:
507
- # # These only show with mypy>=0.730:
508
- # child.expect("==== mypy ====")
509
- # child.expect("Success: no issues found in 1 source file")
510
- try :
511
- child .expect (str (num_tests ) + " passed" )
512
- except pexpect .exceptions .TIMEOUT :
513
- if module_name == "__init__" and (
514
- Version ("6.0" ) <= PYTEST_VERSION < Version ("6.2" )
515
- ):
516
- # MypyItems hit the __init__.py bug too when --looponfail
517
- # re-collects them after the failing file is modified.
518
- # Unlike MypyFile, MypyItem is not a Collector, so this used
519
- # to cause an AttributeError until a workaround was added
520
- # (MypyItem.collect was defined to yield itself).
521
- # Mypy probably noticed the __init__.py problem during the
522
- # development of Pytest 6.0, but the error was addressed
523
- # with an isinstance assertion, which broke the workaround.
524
- # Here, we hit that assertion:
525
- child .expect ("AssertionError" )
526
- child .expect ("1 error" )
527
- pytest .xfail ("https://github.com/pytest-dev/pytest/issues/8016" )
528
- raise
487
+ child .expect ("==== mypy ====" )
488
+ child .expect ("Success: no issues found in 1 source file" )
489
+ child .expect ("2 passed" )
529
490
_expect_waiting ()
530
491
531
492
def _break ():
@@ -550,35 +511,29 @@ def test_mypy_results_from_mypy_with_opts():
550
511
551
512
def test_mypy_no_output (testdir , xdist_args ):
552
513
"""No terminal summary is shown if there is no output from mypy."""
553
- type_ignore = (
554
- "# type: ignore"
555
- if (
556
- PYTEST_VERSION
557
- < Version ("6.0" ) # Pytest didn't add type annotations until 6.0.
558
- )
559
- else ""
560
- )
561
514
testdir .makepyfile (
562
515
# Mypy prints a success message to stderr by default:
563
516
# "Success: no issues found in 1 source file"
564
517
# Clear stderr and unmatched_stdout to simulate mypy having no output:
565
- conftest = f """
566
- import pytest { type_ignore }
518
+ conftest = """
519
+ import pytest
567
520
568
521
@pytest.hookimpl(hookwrapper=True)
569
522
def pytest_terminal_summary(config):
570
- mypy_results_path = getattr(config, "_mypy_results_path", None)
571
- if not mypy_results_path:
523
+ pytest_mypy = config.pluginmanager.getplugin("mypy")
524
+ stash_key = pytest_mypy.stash_keys["mypy_results_path"]
525
+ try:
526
+ mypy_results_path = config.stash[stash_key]
527
+ except KeyError:
572
528
# xdist worker
573
529
return
574
- pytest_mypy = config.pluginmanager.getplugin("mypy")
575
530
with open(mypy_results_path, mode="w") as results_f:
576
531
pytest_mypy.MypyResults(
577
532
opts=[],
578
533
stdout="",
579
534
stderr="",
580
535
status=0,
581
- abspath_errors={{} },
536
+ abspath_errors={},
582
537
unmatched_stdout="",
583
538
).dump(results_f)
584
539
yield
0 commit comments