Skip to content

Commit b4df2b3

Browse files
Enforces having unique test ids in a single namespace (#11687)
I found lots of duplicate test names. It might hide important errors, be hard to reproduce or rerun. Refs #11662 Co-authored-by: Shantanu <[email protected]>
1 parent 9e34f6a commit b4df2b3

27 files changed

+48
-40
lines changed

mypy/test/data.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,13 @@ def split_test_cases(parent: 'DataFileCollector', suite: 'DataSuite',
578578
data,
579579
flags=re.DOTALL | re.MULTILINE)
580580
line_no = cases[0].count('\n') + 1
581+
test_names = set()
581582
for i in range(1, len(cases), NUM_GROUPS):
582583
name, writescache, only_when, platform_flag, skip, xfail, data = cases[i:i + NUM_GROUPS]
584+
if name in test_names:
585+
raise RuntimeError('Found a duplicate test name "{}" in {} on line {}'.format(
586+
name, parent.name, line_no,
587+
))
583588
platform = platform_flag[1:] if platform_flag else None
584589
yield DataDrivenTestCase.from_parent(
585590
parent=parent,
@@ -596,6 +601,9 @@ def split_test_cases(parent: 'DataFileCollector', suite: 'DataSuite',
596601
)
597602
line_no += data.count('\n') + 1
598603

604+
# Record existing tests to prevent duplicates:
605+
test_names.update({name})
606+
599607

600608
class DataSuiteCollector(pytest.Class):
601609
def collect(self) -> Iterator['DataFileCollector']:

test-data/unit/check-abstract.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ a.f(B()) # E: No overload variant of "f" of "A" matches argument type "B" \
600600
# N: def f(self, x: int) -> int \
601601
# N: def f(self, x: str) -> str
602602

603-
[case testOverloadedAbstractMethodVariantMissingDecorator1]
603+
[case testOverloadedAbstractMethodVariantMissingDecorator0]
604604
from foo import *
605605
[file foo.pyi]
606606
from abc import abstractmethod, ABCMeta

test-data/unit/check-attr.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ reveal_type(sub_str.attr) # N: Revealed type is "builtins.str*"
502502
[builtins fixtures/bool.pyi]
503503

504504

505-
[case testAttrsGenericInheritance]
505+
[case testAttrsGenericInheritance2]
506506
from typing import Generic, TypeVar
507507
import attr
508508

test-data/unit/check-class-namedtuple.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ a = A(B())
270270
a = A(1) # E: Argument 1 to "A" has incompatible type "int"; expected "B"
271271
[builtins fixtures/tuple.pyi]
272272

273-
[case testNewNamedTupleProperty]
273+
[case testNewNamedTupleProperty36]
274274
# flags: --python-version 3.6
275275
from typing import NamedTuple
276276

test-data/unit/check-classes.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6463,7 +6463,7 @@ class C(B):
64636463
[out]
64646464
main:4: error: Incompatible types in assignment (expression has type "str", base class "B" defined the type as "int")
64656465

6466-
[case testIgnorePrivateMethodsTypeCheck]
6466+
[case testIgnorePrivateMethodsTypeCheck2]
64676467
class A:
64686468
def __foo_(self) -> int: ...
64696469
class B:

test-data/unit/check-functions.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,7 +1485,7 @@ x = None # type: Any
14851485
if x:
14861486
def f(x: int) -> None: pass # E: All conditional function variants must have identical signatures
14871487

1488-
[case testConditionalRedefinitionOfAnUnconditionalFunctionDefinition1]
1488+
[case testConditionalRedefinitionOfAnUnconditionalFunctionDefinition2]
14891489
from typing import Any
14901490
def f(x: int) -> None: pass # N: "f" defined here
14911491
x = None # type: Any
@@ -2212,7 +2212,7 @@ from typing import Callable
22122212
class A:
22132213
def f(self) -> None:
22142214
# In particular, test that the error message contains "g" of "A".
2215-
self.g() # E: Too few arguments for "g" of "A"
2215+
self.g() # E: Too few arguments for "g" of "A"
22162216
self.g(1)
22172217
@dec
22182218
def g(self, x: str) -> None: pass

test-data/unit/check-generics.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class C: pass
5252
[out]
5353
main:8: error: Incompatible types in assignment (expression has type "C", variable has type "B")
5454

55-
[case testGenericMemberVariable]
55+
[case testGenericMemberVariable2]
5656
from typing import TypeVar, Generic
5757
T = TypeVar('T')
5858
a, b, c = None, None, None # type: (A[B], B, C)
@@ -2118,7 +2118,7 @@ class B(A[T], Generic[T, S]):
21182118
reveal_type(B.foo) # N: Revealed type is "def [T, S] () -> Tuple[T`1, __main__.B[T`1, S`2]]"
21192119
[builtins fixtures/classmethod.pyi]
21202120

2121-
[case testGenericClassAlternativeConstructorPrecise]
2121+
[case testGenericClassAlternativeConstructorPrecise2]
21222122
from typing import Generic, TypeVar, Type, Tuple, Any
21232123

21242124
T = TypeVar('T')

test-data/unit/check-inference.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2614,7 +2614,7 @@ class C(B):
26142614
reveal_type(B.x) # N: Revealed type is "None"
26152615
reveal_type(C.x) # N: Revealed type is "None"
26162616

2617-
[case testLocalPartialTypesWithInheritance2]
2617+
[case testLocalPartialTypesWithInheritance3]
26182618
# flags: --local-partial-types
26192619
from typing import Optional
26202620

@@ -2652,7 +2652,7 @@ class C:
26522652
def f(self, x) -> None:
26532653
C.a.y # E: Item "None" of "Optional[Any]" has no attribute "y"
26542654

2655-
[case testLocalPartialTypesAccessPartialNoneAttribute]
2655+
[case testLocalPartialTypesAccessPartialNoneAttribute2]
26562656
# flags: --local-partial-types
26572657
class C:
26582658
a = None # E: Need type annotation for "a"

test-data/unit/check-modules.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- Type checker test cases dealing with modules and imports.
22
-- Towards the end there are tests for PEP 420 (namespace packages, i.e. __init__.py-less packages).
33

4-
[case testAccessImportedDefinitions]
4+
[case testAccessImportedDefinitions0]
55
import m
66
import typing
77
m.f() # E: Missing positional argument "a" in call to "f"
@@ -14,7 +14,7 @@ class A: pass
1414
def f(a: A) -> None: pass
1515
x = A()
1616

17-
[case testAccessImportedDefinitions]
17+
[case testAccessImportedDefinitions1]
1818
import m
1919
import typing
2020
m.f(object()) # E: Argument 1 to "f" has incompatible type "object"; expected "A"

test-data/unit/check-multiple-inheritance.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ class A(Base1, Base2):
502502
[out]
503503
main:10: error: Incompatible types in assignment (expression has type "GenericBase[Base2]", base class "Base1" defined the type as "GenericBase[Base1]")
504504

505-
[case testMultipleInheritance_NestedVariableOverriddenWithCompatibleType]
505+
[case testMultipleInheritance_NestedVariableOverriddenWithCompatibleType2]
506506
from typing import TypeVar, Generic
507507
T = TypeVar('T', covariant=True)
508508
class GenericBase(Generic[T]):

0 commit comments

Comments
 (0)