Skip to content

Commit 7be61ff

Browse files
committed
Pollute empty directory for test speedup
1 parent 00c058b commit 7be61ff

File tree

2 files changed

+41
-13
lines changed

2 files changed

+41
-13
lines changed

ci.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ else
103103
INSTALLDIR=$(python -c "import os, trio; print(os.path.dirname(trio.__file__))")
104104
cp ../pyproject.toml $INSTALLDIR
105105

106+
# TODO: remove this once we have a py.typed file
107+
touch "$INSTALLDIR/py.typed"
108+
109+
# get mypy tests a nice cache
110+
MYPYPATH=".." mypy --config-file= --cache-dir=./.mypy_cache -c "import trio" >/dev/null 2>/dev/null || true
111+
106112
if pytest -r a -p trio._tests.pytest_plugin --junitxml=../test-results.xml --run-slow ${INSTALLDIR} --cov="$INSTALLDIR" --cov-report=xml --cov-config=../.coveragerc --verbose; then
107113
PASSED=true
108114
else

trio/_tests/test_exports.py

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
from .._core._tests.tutil import slow
1919
from .pytest_plugin import RUN_SLOW
2020

21+
mypy_cache_updated = False
22+
2123

2224
def test_core_is_properly_reexported():
2325
# Each export from _core should be re-exported by exactly one of these
@@ -59,8 +61,8 @@ def public_modules(module):
5961
# won't be reflected in trio.socket, and this shouldn't cause downstream test
6062
# runs to start failing.
6163
@pytest.mark.redistributors_should_skip
62-
# pylint/jedi often have trouble with alpha releases, where Python's internals
63-
# are in flux, grammar may not have settled down, etc.
64+
# Static analysis tools often have trouble with alpha releases, where Python's
65+
# internals are in flux, grammar may not have settled down, etc.
6466
@pytest.mark.skipif(
6567
sys.version_info.releaselevel == "alpha",
6668
reason="skip static introspection tools on Python dev/alpha releases",
@@ -72,6 +74,7 @@ def public_modules(module):
7274
"ignore:module 'sre_constants' is deprecated:DeprecationWarning",
7375
)
7476
def test_static_tool_sees_all_symbols(tool, modname, tmpdir):
77+
global mypy_cache_updated
7578
module = importlib.import_module(modname)
7679

7780
def no_underscores(symbols):
@@ -109,12 +112,20 @@ def no_underscores(symbols):
109112
if sys.implementation.name != "cpython":
110113
pytest.skip("mypy not installed in tests on pypy")
111114

112-
cache = Path(tmpdir / "cache")
113-
cache.mkdir()
115+
cache = Path.cwd() / ".mypy_cache"
114116
from mypy.api import run
115117

116-
# pollute CWD with `.mypy_cache`? TODO think about it
117-
run(["--config-file=", f"--cache-dir={cache}", "-c", f"import {modname}"])
118+
# This pollutes the `empty` dir. Should this be changed?
119+
if not mypy_cache_updated:
120+
run(
121+
[
122+
"--config-file=",
123+
"--cache-dir=./.mypy_cache",
124+
"-c",
125+
f"import {modname}",
126+
]
127+
)
128+
mypy_cache_updated = True
118129

119130
trio_cache = next(cache.glob("*/trio"))
120131
_, modname = (modname + ".").split(".", 1)
@@ -189,15 +200,16 @@ def no_underscores(symbols):
189200
@slow
190201
# see comment on test_static_tool_sees_all_symbols
191202
@pytest.mark.redistributors_should_skip
192-
# jedi/mypy often have trouble with alpha releases, where Python's internals
193-
# are in flux, grammar may not have settled down, etc.
203+
# Static analysis tools often have trouble with alpha releases, where Python's
204+
# internals are in flux, grammar may not have settled down, etc.
194205
@pytest.mark.skipif(
195206
sys.version_info.releaselevel == "alpha",
196207
reason="skip static introspection tools on Python dev/alpha releases",
197208
)
198209
@pytest.mark.parametrize("module_name", PUBLIC_MODULE_NAMES)
199210
@pytest.mark.parametrize("tool", ["jedi", "mypy"])
200211
def test_static_tool_sees_class_members(tool, module_name, tmpdir) -> None:
212+
global mypy_cache_updated
201213
module = PUBLIC_MODULES[PUBLIC_MODULE_NAMES.index(module_name)]
202214

203215
# ignore hidden, but not dunder, symbols
@@ -219,12 +231,22 @@ def no_hidden(symbols):
219231
if not py_typed_exists: # pragma: no branch
220232
py_typed_path.write_text("")
221233

222-
cache = Path(tmpdir / "cache")
223-
cache.mkdir()
234+
cache = Path.cwd() / ".mypy_cache"
224235
from mypy.api import run
225236

226-
# pollute CWD with `.mypy_cache`? TODO think about it
227-
run(["--config-file=", f"--cache-dir={cache}", "-c", f"import {module_name}"])
237+
# This pollutes the `empty` dir. Should this be changed?
238+
if not mypy_cache_updated: # pragma: no cover
239+
# mypy cache was *probably* already updated by the other tests,
240+
# but `pytest -k ...` might run just this test on its own
241+
run(
242+
[
243+
"--config-file=",
244+
"--cache-dir=./.mypy_cache",
245+
"-c",
246+
f"import {module_name}",
247+
]
248+
)
249+
mypy_cache_updated = True
228250

229251
trio_cache = next(cache.glob("*/trio"))
230252
modname = module_name
@@ -244,7 +266,7 @@ def no_hidden(symbols):
244266
@functools.lru_cache()
245267
def lookup_symbol(symbol):
246268
topname, *modname, name = symbol.split(".")
247-
version = next(cache.glob("*.*/"))
269+
version = next(cache.glob("3.*/"))
248270
mod_cache = version / topname
249271
if not mod_cache.is_dir():
250272
mod_cache = version / (topname + ".data.json")

0 commit comments

Comments
 (0)