Skip to content

Commit fa1803d

Browse files
Key test mypy cache dirs by settings content (#3516)
1 parent 5ae7cea commit fa1803d

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

scripts/tests_extension_hook.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import hashlib
34
from typing import TYPE_CHECKING
45

56
from pytest_mypy_plugins.collect import File
@@ -13,6 +14,12 @@ def django_plugin_hook(test_item: YamlTestItem) -> None:
1314
installed_apps = test_item.parsed_test_data.get("installed_apps", None)
1415
monkeypatch = test_item.parsed_test_data.get("monkeypatch", False)
1516

17+
# When the result of `Plugin.report_config_data` changes, the mypy cache is invalidated.
18+
# This slows down the test suite because test can be executed in any order, regularly invalidating shared cache.
19+
# To mitigate this, use different cache dirs based on the settings.
20+
config_hash = hashlib.md5(f"{installed_apps}{custom_settings}".encode(), usedforsecurity=False).hexdigest()[:10]
21+
test_item.incremental_cache_dir += config_hash
22+
1623
if installed_apps and custom_settings:
1724
raise ValueError('"installed_apps" and "custom_settings" are not compatible, please use one or the other')
1825

0 commit comments

Comments
 (0)