From 1f75b1f9abc16e4103ce6af5665200a7bdc08fc6 Mon Sep 17 00:00:00 2001 From: A5rocks Date: Sat, 24 Jun 2023 07:09:25 +0900 Subject: [PATCH] Only make sure mypy cache is up to date once --- trio/_tests/test_exports.py | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/trio/_tests/test_exports.py b/trio/_tests/test_exports.py index ec29aba3a6..b9c12e1b82 100644 --- a/trio/_tests/test_exports.py +++ b/trio/_tests/test_exports.py @@ -18,6 +18,8 @@ from .._core._tests.tutil import slow from .pytest_plugin import RUN_SLOW +mypy_cache_updated = False + def test_core_is_properly_reexported(): # Each export from _core should be re-exported by exactly one of these @@ -72,6 +74,7 @@ def public_modules(module): "ignore:module 'sre_constants' is deprecated:DeprecationWarning", ) def test_static_tool_sees_all_symbols(tool, modname, tmpdir): + global mypy_cache_updated module = importlib.import_module(modname) def no_underscores(symbols): @@ -113,7 +116,16 @@ def no_underscores(symbols): from mypy.api import run # This pollutes the `empty` dir. Should this be changed? - run(["--config-file=", "--cache-dir=./.mypy_cache", "-c", f"import {modname}"]) + if not mypy_cache_updated: + run( + [ + "--config-file=", + "--cache-dir=./.mypy_cache", + "-c", + f"import {modname}", + ] + ) + mypy_cache_updated = True trio_cache = next(cache.glob("*/trio")) _, modname = (modname + ".").split(".", 1) @@ -197,6 +209,7 @@ def no_underscores(symbols): @pytest.mark.parametrize("module_name", PUBLIC_MODULE_NAMES) @pytest.mark.parametrize("tool", ["jedi", "mypy"]) def test_static_tool_sees_class_members(tool, module_name, tmpdir) -> None: + global mypy_cache_updated module = PUBLIC_MODULES[PUBLIC_MODULE_NAMES.index(module_name)] # ignore hidden, but not dunder, symbols @@ -222,14 +235,16 @@ def no_hidden(symbols): from mypy.api import run # This pollutes the `empty` dir. Should this be changed? - run( - [ - "--config-file=", - "--cache-dir=./.mypy_cache", - "-c", - f"import {module_name}", - ] - ) + if not mypy_cache_updated: + run( + [ + "--config-file=", + "--cache-dir=./.mypy_cache", + "-c", + f"import {module_name}", + ] + ) + mypy_cache_updated = False trio_cache = next(cache.glob("*/trio")) modname = module_name