Handle the end of the session.
(session, exitstatus)
| 1023 | |
| 1024 | |
| 1025 | def pytest_sessionfinish(session, exitstatus): |
| 1026 | """Handle the end of the session.""" |
| 1027 | n = session.config.option.durations |
| 1028 | if n is None: |
| 1029 | return |
| 1030 | print("\n") |
| 1031 | # get the number to print |
| 1032 | files = defaultdict(lambda: 0.0) |
| 1033 | for item in session.items: |
| 1034 | if _phase_report_key not in item.stash: |
| 1035 | continue |
| 1036 | report = item.stash[_phase_report_key] |
| 1037 | dur = sum(x.duration for x in report.values()) |
| 1038 | parts = Path(item.nodeid.split(":")[0]).parts |
| 1039 | # split mne/tests/test_whatever.py into separate categories since these |
| 1040 | # are essentially submodule-level tests. Keeping just [:3] works, |
| 1041 | # except for mne/viz where we want level-4 granulatity |
| 1042 | split_submodules = (("mne", "viz"), ("mne", "preprocessing")) |
| 1043 | parts = parts[: 4 if parts[:2] in split_submodules else 3] |
| 1044 | if not parts[-1].endswith(".py"): |
| 1045 | parts = parts + ("",) |
| 1046 | file_key = "/".join(parts) |
| 1047 | files[file_key] += dur |
| 1048 | files = sorted(list(files.items()), key=lambda x: x[1])[::-1] |
| 1049 | |
| 1050 | _files[:] = files[:n] |
| 1051 | |
| 1052 | |
| 1053 | def pytest_terminal_summary(terminalreporter, exitstatus, config): |