Creates a map from a list of tests to run to easily split them by category, when running parallelism of slow tests. Args: test_files_to_run (`List[str]`): The list of tests to run. json_output_file (`str`): The path where to store the built json map.
(test_files_to_run: List[str], json_output_file: Optional[str] = None)
| 865 | |
| 866 | |
| 867 | def create_json_map(test_files_to_run: List[str], json_output_file: Optional[str] = None): |
| 868 | """ |
| 869 | Creates a map from a list of tests to run to easily split them by category, when running parallelism of slow tests. |
| 870 | |
| 871 | Args: |
| 872 | test_files_to_run (`List[str]`): The list of tests to run. |
| 873 | json_output_file (`str`): The path where to store the built json map. |
| 874 | """ |
| 875 | if json_output_file is None: |
| 876 | return |
| 877 | |
| 878 | test_map = {} |
| 879 | for test_file in test_files_to_run: |
| 880 | # `test_file` is a path to a test folder/file, starting with `tests/`. For example, |
| 881 | # - `tests/models/bert/test_modeling_bert.py` or `tests/models/bert` |
| 882 | # - `tests/trainer/test_trainer.py` or `tests/trainer` |
| 883 | # - `tests/test_modeling_common.py` |
| 884 | names = test_file.split(os.path.sep) |
| 885 | module = names[1] |
| 886 | if module in MODULES_TO_IGNORE: |
| 887 | continue |
| 888 | |
| 889 | if len(names) > 2 or not test_file.endswith(".py"): |
| 890 | # test folders under `tests` or python files under them |
| 891 | # take the part like tokenization, `pipeline`, etc. for other test categories |
| 892 | key = os.path.sep.join(names[1:2]) |
| 893 | else: |
| 894 | # common test files directly under `tests/` |
| 895 | key = "common" |
| 896 | |
| 897 | if key not in test_map: |
| 898 | test_map[key] = [] |
| 899 | test_map[key].append(test_file) |
| 900 | |
| 901 | # sort the keys & values |
| 902 | keys = sorted(test_map.keys()) |
| 903 | test_map = {k: " ".join(sorted(test_map[k])) for k in keys} |
| 904 | |
| 905 | with open(json_output_file, "w", encoding="UTF-8") as fp: |
| 906 | json.dump(test_map, fp, ensure_ascii=False) |
| 907 | |
| 908 | |
| 909 | def infer_tests_to_run( |
no outgoing calls
no test coverage detected