@@ -69,9 +69,16 @@ def collect_cases(fn: Callable[..., Iterator[Case]]) -> Callable[..., None]:
69
69
70
70
def test (* args : Any , ** kwargs : Any ) -> None :
71
71
cases = list (fn (* args , ** kwargs ))
72
- expected_errors = set (
73
- "{}.{}" .format (TEST_MODULE_NAME , c .error ) for c in cases if c .error is not None
74
- )
72
+ expected_errors = set ()
73
+ for c in cases :
74
+ if c .error is None :
75
+ continue
76
+ expected_error = "{}.{}" .format (TEST_MODULE_NAME , c .error )
77
+ assert expected_error not in expected_errors , (
78
+ "collect_cases merges cases into a single stubtest invocation; we already "
79
+ "expect an error for {}" .format (expected_error )
80
+ )
81
+ expected_errors .add (expected_error )
75
82
output = run_stubtest (
76
83
stub = "\n \n " .join (textwrap .dedent (c .stub .lstrip ("\n " )) for c in cases ),
77
84
runtime = "\n \n " .join (textwrap .dedent (c .runtime .lstrip ("\n " )) for c in cases ),
@@ -582,6 +589,11 @@ def h(x: str): ...
582
589
stub = "from mystery import A, B as B, C as D # type: ignore" , runtime = "" , error = "B"
583
590
)
584
591
592
+ @collect_cases
593
+ def test_missing_no_runtime_all (self ) -> Iterator [Case ]:
594
+ yield Case (stub = "" , runtime = "import sys" , error = None )
595
+ yield Case (stub = "" , runtime = "def g(): ..." , error = "g" )
596
+
585
597
@collect_cases
586
598
def test_name_mangling (self ) -> Iterator [Case ]:
587
599
yield Case (
@@ -666,6 +678,11 @@ def test_ignore_flags(self) -> None:
666
678
)
667
679
assert not output
668
680
681
+ output = run_stubtest (
682
+ stub = "" , runtime = "def f(): pass" , options = ["--ignore-missing-stub" ]
683
+ )
684
+ assert not output
685
+
669
686
output = run_stubtest (
670
687
stub = "def f(__a): ..." , runtime = "def f(a): pass" , options = ["--ignore-positional-only" ]
671
688
)
0 commit comments