Skip to content

Commit 03588e7

Browse files
elazargmsullivan
authored andcommitted
Lazy tests: parse using regex first (#5459)
Parse tests on collection only enough to find the name, so small number of tests run faster On my machine, `pytest -n0 -k testAttrsSimple` takes at least 2.24 seconds to finish on master, and at most 0.95 seconds to finish with this PR. - 'skip-cache' is changed to 'only_when_nocache' and similarly 'skip-nocache' - I have replace while loops with "if True" to make the diff simpler. Further cleanup and optimizations are also possible Fixes #1073
1 parent b923c58 commit 03588e7

File tree

7 files changed

+207
-229
lines changed

7 files changed

+207
-229
lines changed

mypy/test/data.py

Lines changed: 171 additions & 193 deletions
Large diffs are not rendered by default.

mypy/test/testcheck.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def run_case_once(self, testcase: DataDrivenTestCase,
144144
else:
145145
options.incremental = False
146146
# Don't waste time writing cache unless we are specifically looking for it
147-
if 'writescache' not in testcase.name.lower():
147+
if not testcase.writescache:
148148
options.cache_dir = os.devnull
149149

150150
sources = []

mypy/test/testcmdline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def test_python_cmdline(testcase: DataDrivenTestCase) -> None:
7878
actual_output_content = output_file.read().splitlines()
7979
normalized_output = normalize_file_output(actual_output_content,
8080
os.path.abspath(test_temp_dir))
81-
if testcase.native_sep and os.path.sep == '\\':
81+
if testcase.suite.native_sep and os.path.sep == '\\':
8282
normalized_output = [fix_cobertura_filename(line) for line in normalized_output]
8383
normalized_output = normalize_error_messages(normalized_output)
8484
assert_string_arrays_equal(expected_content.splitlines(), normalized_output,

mypy/test/testfinegrained.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ class FineGrainedSuite(DataSuite):
5555
# as skipped, not just elided.
5656
def should_skip(self, testcase: DataDrivenTestCase) -> bool:
5757
if self.use_cache:
58-
if testcase.name.endswith("-skip-cache"):
58+
if testcase.only_when == '-only_when_nocache':
5959
return True
6060
# TODO: In caching mode we currently don't well support
6161
# starting from cached states with errors in them.
6262
if testcase.output and testcase.output[0] != '==':
6363
return True
6464
else:
65-
if testcase.name.endswith("-skip-nocache"):
65+
if testcase.only_when == '-only_when_cache':
6666
return True
6767

6868
return False

test-data/unit/fine-grained-blockers.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ a.py:1: error: invalid syntax
237237
b.py:3: error: Too many arguments for "f"
238238
a.py:3: error: Too many arguments for "g"
239239

240-
[case testDeleteFileWithBlockingError-skip-cache]
240+
[case testDeleteFileWithBlockingError-only_when_nocache]
241241
-- Different cache/no-cache tests because:
242242
-- Error message ordering differs
243243
import a
@@ -258,7 +258,7 @@ main:1: error: Cannot find module named 'a'
258258
main:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help)
259259
b.py:1: error: Cannot find module named 'a'
260260

261-
[case testDeleteFileWithBlockingError-skip-nocache]
261+
[case testDeleteFileWithBlockingError-only_when_cache]
262262
-- Different cache/no-cache tests because:
263263
-- Error message ordering differs
264264
import a
@@ -331,7 +331,7 @@ import blocker2
331331
==
332332
a.py:1: error: "int" not callable
333333

334-
[case testFixingBlockingErrorTriggersDeletion1-skip-cache]
334+
[case testFixingBlockingErrorTriggersDeletion1-only_when_nocache]
335335
-- Disabled in cache mdode:
336336
-- Cache mode fails to produce the error in the final step, but this is
337337
-- a manifestation of a bug that can occur in no-cache mode also.

test-data/unit/fine-grained-modules.test

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ main:1: error: Cannot find module named 'a'
392392
main:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help)
393393
==
394394

395-
[case testDeletionOfSubmoduleTriggersImportFrom1-skip-cache]
395+
[case testDeletionOfSubmoduleTriggersImportFrom1-only_when_nocache]
396396
-- Different cache/no-cache tests because:
397397
-- missing module error message mismatch
398398
from p import q
@@ -410,7 +410,7 @@ main:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports"
410410

411411
-- TODO: Fix this bug. It is a real bug that was been papered over
412412
-- by the test harness.
413-
[case testDeletionOfSubmoduleTriggersImportFrom1-skip-nocache-skip]
413+
[case testDeletionOfSubmoduleTriggersImportFrom1-only_when_cache-skip]
414414
-- Different cache/no-cache tests because:
415415
-- missing module error message mismatch
416416
from p import q
@@ -1019,7 +1019,7 @@ a/b.py:3: error: Revealed type is 'Any'
10191019
==
10201020
a/b.py:3: error: Unsupported operand types for + ("int" and "str")
10211021

1022-
[case testDeleteModuleWithinPackageInitIgnored-skip-cache]
1022+
[case testDeleteModuleWithinPackageInitIgnored-only_when_nocache]
10231023
-- Disabled in cache mode because incorrect behavior:
10241024
-- Having deleted files specified on command line seems dodgy, though.
10251025
# cmd: mypy x.py a/b.py
@@ -1217,7 +1217,7 @@ main:2: error: Too few arguments for "foo" of "Foo"
12171217
-- does not appear in the cache, for cache mode. They are run in
12181218
-- cache mode only because stale and rechecked differ heavily between
12191219
-- the modes.
1220-
[case testAddModuleAfterCache1-skip-nocache]
1220+
[case testAddModuleAfterCache1-only_when_cache]
12211221
# cmd: mypy main a.py
12221222
# cmd2: mypy main a.py b.py
12231223
# cmd3: mypy main a.py b.py
@@ -1244,7 +1244,7 @@ def foo(x: int) -> None: pass
12441244
a.py:2: error: Too many arguments for "foo"
12451245
==
12461246

1247-
[case testAddModuleAfterCache2-skip-nocache]
1247+
[case testAddModuleAfterCache2-only_when_cache]
12481248
# cmd: mypy main a.py
12491249
# cmd2: mypy main a.py b.py
12501250
# cmd3: mypy main a.py b.py
@@ -1269,7 +1269,7 @@ def foo(x: int) -> None: pass
12691269
a.py:2: error: Too many arguments for "foo"
12701270
==
12711271

1272-
[case testAddModuleAfterCache3-skip-nocache]
1272+
[case testAddModuleAfterCache3-only_when_cache]
12731273
# cmd: mypy main a.py
12741274
# cmd2: mypy main a.py b.py c.py d.py e.py f.py g.py
12751275
# cmd3: mypy main a.py b.py c.py d.py e.py f.py g.py
@@ -1300,7 +1300,7 @@ a.py:2: error: Too many arguments for "foo"
13001300
==
13011301

13021302

1303-
[case testAddModuleAfterCache4-skip-nocache]
1303+
[case testAddModuleAfterCache4-only_when_cache]
13041304
# cmd: mypy main a.py
13051305
# cmd2: mypy main a.py b.py
13061306
# cmd3: mypy main a.py b.py
@@ -1319,7 +1319,7 @@ def foo(x: int) -> None: pass
13191319
b.py:2: error: Too many arguments for "foo"
13201320
==
13211321

1322-
[case testAddModuleAfterCache5-skip-nocache]
1322+
[case testAddModuleAfterCache5-only_when_cache]
13231323
# cmd: mypy main a.py
13241324
# cmd2: mypy main a.py b.py
13251325
# cmd3: mypy main a.py b.py
@@ -1346,7 +1346,7 @@ def foo(x: int) -> None: pass
13461346
b.py:2: error: Too many arguments for "foo"
13471347
==
13481348

1349-
[case testAddModuleAfterCache6-skip-nocache]
1349+
[case testAddModuleAfterCache6-only_when_cache]
13501350
# cmd: mypy main a.py
13511351
# cmd2: mypy main a.py b.py
13521352
# cmd3: mypy main a.py b.py
@@ -1374,7 +1374,7 @@ def foo(x: int) -> None: pass
13741374
a.py:2: error: Too many arguments for "foo"
13751375
==
13761376

1377-
[case testRenameAndDeleteModuleAfterCache-skip-nocache]
1377+
[case testRenameAndDeleteModuleAfterCache-only_when_cache]
13781378
import a
13791379
[file a.py]
13801380
from b1 import f
@@ -1394,7 +1394,7 @@ f()
13941394
[out]
13951395
==
13961396

1397-
[case testDeleteModuleAfterCache-skip-nocache]
1397+
[case testDeleteModuleAfterCache-only_when_cache]
13981398
import a
13991399
[file a.py]
14001400
from b import f

test-data/unit/fine-grained.test

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
-- incremental runs is not yet supported.
3737
--
3838
-- Each test case run without caching and with caching (if the initial run passes),
39-
-- unless it has one a --skip-cache or --skip-nocache suffix. We sometimes
39+
-- unless it has one a -only_when_cache or -only_when_nocache arguments. We sometimes
4040
-- skip caching test cases to speed up tests, if the caching variant is not useful.
4141
-- The caching test case variants get an implicit _cached suffix.
4242

@@ -313,7 +313,7 @@ main:5: error: Module has no attribute "B"
313313
==
314314
main:5: error: Module has no attribute "B"
315315

316-
[case testContinueToReportErrorAtTopLevel-skip-cache]
316+
[case testContinueToReportErrorAtTopLevel-only_when_nocache]
317317
-- Different cache/no-cache tests because:
318318
-- Error message ordering differs
319319
import n
@@ -338,7 +338,7 @@ n.py:2: error: "A" has no attribute "g"
338338
==
339339
n.py:2: error: "A" has no attribute "g"
340340

341-
[case testContinueToReportErrorAtTopLevel-skip-nocache]
341+
[case testContinueToReportErrorAtTopLevel-only_when_cache]
342342
-- Different cache/no-cache tests because:
343343
-- Error message ordering differs
344344
import n
@@ -4556,7 +4556,7 @@ def g(x: T) -> T:
45564556
==
45574557
a.py:2: error: Value of type variable "T" of function cannot be "int"
45584558

4559-
[case testGenericFineCallableBoundDeleted-skip-nocache]
4559+
[case testGenericFineCallableBoundDeleted-only_when_cache]
45604560
# See https://github.com/python/mypy/issues/4783
45614561
import a
45624562
[file a.py]
@@ -5953,7 +5953,7 @@ class C:
59535953
==
59545954
a.py:4: error: Argument 1 to "func" has incompatible type "B"; expected "P"
59555955

5956-
[case testTwoProtocolsTwoFilesCrossedUpdateType-skip-cache]
5956+
[case testTwoProtocolsTwoFilesCrossedUpdateType-only_when_nocache]
59575957
# this test and the next one (TwoProtocolsTwoFilesCrossedDeleteAttr) has errors ordered
59585958
# opposite way with and without cache, therefore skip one of each.
59595959
import a
@@ -5991,7 +5991,7 @@ b2.py:7: error: Argument 1 to "f" has incompatible type "D"; expected "P1"
59915991
b2.py:7: note: Following member(s) of "D" have conflicts:
59925992
b2.py:7: note: x: expected "int", got "str"
59935993

5994-
[case testTwoProtocolsTwoFilesCrossedDeleteAttr-skip-nocache]
5994+
[case testTwoProtocolsTwoFilesCrossedDeleteAttr-only_when_cache]
59955995
import a
59965996
[file a.py]
59975997
import b1
@@ -6732,7 +6732,7 @@ def g(x: str) -> str: pass
67326732
==
67336733
main:2: error: Argument 1 to "g" has incompatible type "int"; expected "str"
67346734

6735-
[case testExtendedUnpacking-skip-cache]
6735+
[case testExtendedUnpacking-only_when_nocache]
67366736
from typing import List
67376737
from a import g
67386738
def f() -> List[int]:
@@ -6752,7 +6752,7 @@ def g() -> Tuple[str, str]: pass
67526752
==
67536753
main:5: error: Incompatible return value type (got "List[str]", expected "List[int]")
67546754

6755-
[case testUnpackInExpression1-skip-cache]
6755+
[case testUnpackInExpression1-only_when_nocache]
67566756
from typing import Tuple, List
67576757
from a import t
67586758

@@ -6776,7 +6776,7 @@ def t() -> Tuple[str]: ...
67766776
main:5: error: Incompatible return value type (got "Tuple[int, str]", expected "Tuple[int, int]")
67776777
main:8: error: List item 1 has incompatible type "Tuple[str]"; expected "int"
67786778

6779-
[case testUnpackInExpression2-skip-cache]
6779+
[case testUnpackInExpression2-only_when_nocache]
67806780
from typing import Set
67816781
from a import t
67826782

@@ -6796,7 +6796,7 @@ def t() -> Tuple[str]: pass
67966796
==
67976797
main:5: error: Argument 2 to <set> has incompatible type "*Tuple[str]"; expected "int"
67986798

6799-
[case testUnpackInExpression3-skip-cache]
6799+
[case testUnpackInExpression3-only_when_nocache]
68006800
from typing import Dict
68016801
from a import d
68026802

@@ -6816,7 +6816,7 @@ def d() -> Dict[int, int]: pass
68166816
==
68176817
main:5: error: Argument 1 to "update" of "dict" has incompatible type "Dict[int, int]"; expected "Mapping[int, str]"
68186818

6819-
[case testAwaitAndAsyncDef-skip-cache]
6819+
[case testAwaitAndAsyncDef-only_when_nocache]
68206820
from a import g
68216821

68226822
async def f() -> int:
@@ -6836,7 +6836,7 @@ async def g() -> str:
68366836
==
68376837
main:4: error: Incompatible return value type (got "str", expected "int")
68386838

6839-
[case testAwaitAnd__await__-skip-cache]
6839+
[case testAwaitAnd__await__-only_when_nocache]
68406840
from a import C
68416841

68426842
async def f(c: C) -> int:
@@ -6899,7 +6899,7 @@ main:6: error: Incompatible return value type (got "str", expected "int")
68996899
==
69006900
main:6: error: Incompatible return value type (got "object", expected "int")
69016901

6902-
[case testAsyncWith2-skip-cache]
6902+
[case testAsyncWith2-only_when_nocache]
69036903
from a import C
69046904

69056905
async def f() -> int:
@@ -7005,7 +7005,7 @@ main:7: error: Unsupported operand types for + ("str" and "int")
70057005
==
70067006
main:5: error: Return type of "m" incompatible with supertype "B"
70077007

7008-
[case testLiskovFineVariableClean-skip-cache]
7008+
[case testLiskovFineVariableClean-only_when_nocache]
70097009
import b
70107010
class A(b.B):
70117011
x: str
@@ -7019,7 +7019,7 @@ class B:
70197019
==
70207020
main:3: error: Incompatible types in assignment (expression has type "str", base class "B" defined the type as "int")
70217021

7022-
[case testLiskovFineVariableCleanDefInMethod-skip-cache]
7022+
[case testLiskovFineVariableCleanDefInMethod-only_when_nocache]
70237023
import b
70247024
class A(b.B):
70257025
def meth(self) -> None:
@@ -7034,7 +7034,7 @@ class B:
70347034
==
70357035
main:4: error: Incompatible types in assignment (expression has type "str", base class "B" defined the type as "int")
70367036

7037-
[case testLiskovFineVariableCleanDefInMethodNested-skip-cache]
7037+
[case testLiskovFineVariableCleanDefInMethodNested-only_when_nocache]
70387038
from b import B
70397039
def outer() -> None:
70407040
class A(B):
@@ -7050,7 +7050,7 @@ class B:
70507050
==
70517051
main:5: error: Incompatible types in assignment (expression has type "str", base class "B" defined the type as "int")
70527052

7053-
[case testLiskovFineVariableInFunctionClean-skip-cache]
7053+
[case testLiskovFineVariableInFunctionClean-only_when_nocache]
70547054
from b import B
70557055
def outer() -> None:
70567056
class A(B):
@@ -7065,7 +7065,7 @@ class B:
70657065
==
70667066
main:4: error: Incompatible types in assignment (expression has type "str", base class "B" defined the type as "int")
70677067

7068-
[case testLiskovFineDecoratorClean-skip-cache]
7068+
[case testLiskovFineDecoratorClean-only_when_nocache]
70697069
import b
70707070
from c import deco
70717071
class A(b.B):

0 commit comments

Comments
 (0)