Clears the cache and run mypy before running any of the typing tests. The mypy results are cached in `OUTPUT_MYPY` for further use. The cache refresh can be skipped using NUMPY_TYPING_TEST_CLEAR_CACHE=0 pytest numpy/typing/tests
()
| 70 | |
| 71 | @pytest.fixture(scope="module", autouse=True) |
| 72 | def run_mypy() -> None: |
| 73 | """Clears the cache and run mypy before running any of the typing tests. |
| 74 | |
| 75 | The mypy results are cached in `OUTPUT_MYPY` for further use. |
| 76 | |
| 77 | The cache refresh can be skipped using |
| 78 | |
| 79 | NUMPY_TYPING_TEST_CLEAR_CACHE=0 pytest numpy/typing/tests |
| 80 | """ |
| 81 | if ( |
| 82 | os.path.isdir(CACHE_DIR) |
| 83 | and bool(os.environ.get("NUMPY_TYPING_TEST_CLEAR_CACHE", True)) |
| 84 | ): |
| 85 | shutil.rmtree(CACHE_DIR) |
| 86 | |
| 87 | split_pattern = re.compile(r"(\s+)?\^(\~+)?") |
| 88 | for directory in (PASS_DIR, REVEAL_DIR, FAIL_DIR, MISC_DIR): |
| 89 | # Run mypy |
| 90 | stdout, stderr, exit_code = api.run([ |
| 91 | "--config-file", |
| 92 | MYPY_INI, |
| 93 | "--cache-dir", |
| 94 | CACHE_DIR, |
| 95 | directory, |
| 96 | ]) |
| 97 | if stderr: |
| 98 | pytest.fail(f"Unexpected mypy standard error\n\n{stderr}", False) |
| 99 | elif exit_code not in {0, 1}: |
| 100 | pytest.fail(f"Unexpected mypy exit code: {exit_code}\n\n{stdout}", False) |
| 101 | |
| 102 | str_concat = "" |
| 103 | filename: str | None = None |
| 104 | for i in stdout.split("\n"): |
| 105 | if "note:" in i: |
| 106 | continue |
| 107 | if filename is None: |
| 108 | filename = _key_func(i) |
| 109 | |
| 110 | str_concat += f"{i}\n" |
| 111 | if split_pattern.match(i) is not None: |
| 112 | OUTPUT_MYPY[filename].append(str_concat) |
| 113 | str_concat = "" |
| 114 | filename = None |
| 115 | |
| 116 | |
| 117 | def get_test_cases(*directories: str) -> list["ParameterSet"]: |