Skip to content

Commit

Permalink
MAINT: Show test timings (mne-tools#8240)
Browse files Browse the repository at this point in the history
* MAINT: Show test timings

* FIX: Need full checkout

* FIX: Better paths
  • Loading branch information
larsoner authored Sep 11, 2020
1 parent 4d02d02 commit e63190c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ omit =
*/setup.py
*/mne/fixes*
*/mne/utils/linalg.py
*/mne/conftest.py

[report]
exclude_lines =
Expand Down
39 changes: 39 additions & 0 deletions mne/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import gc
import os
import os.path as op
from pathlib import Path
import shutil
import sys
import warnings
Expand All @@ -27,6 +28,7 @@
import numpy as np
import mne
from mne.datasets import testing
from mne.utils import _pl

test_path = testing.data_path(download=False)
s_path = op.join(test_path, 'MEG', 'sample')
Expand Down Expand Up @@ -467,3 +469,40 @@ def _fail(*args, **kwargs):
def download_is_error(monkeypatch):
"""Prevent downloading by raising an error when it's attempted."""
monkeypatch.setattr(mne.utils.fetching, '_get_http', _fail)


def pytest_sessionfinish(session, exitstatus):
"""Handle the end of the session."""
n = session.config.option.durations
if n is None:
return
try:
import pytest_harvest
except ImportError:
print('Module-level timings require pytest-harvest')
return
from py.io import TerminalWriter
# get the number to print
writer = TerminalWriter()
res = pytest_harvest.get_session_synthesis_dct(session)
files = dict()
for key, val in res.items():
parts = Path(key.split(':')[0]).parts
# split mne/tests/test_whatever.py into separate categories since these
# are essentially submodule-level tests. Keeping just [:3] works.
parts = parts[:3]
if not parts[-1].endswith('.py'):
parts = parts + ('',)
file_key = '/'.join(parts)
files[file_key] = files.get(file_key, 0) + val['pytest_duration_s']
files = sorted(list(files.items()), key=lambda x: x[1])[::-1]
# print
files = files[:n]
writer.line() # newline
writer.sep('=', f'slowest {n} test module{_pl(n)}')
names, timings = zip(*files)
timings = [f'{timing:0.2f}s total' for timing in timings]
rjust = max(len(timing) for timing in timings)
timings = [timing.rjust(rjust) for timing in timings]
for name, timing in zip(names, timings):
writer.line(f'{timing.ljust(15)}{name}')
1 change: 1 addition & 0 deletions requirements_testing.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pytest!=4.6.0
pytest-cov
pytest-timeout
git+https://github.com/larsoner/python-pytest-harvest@doctest
flake8
flake8-array-spacing
https://github.com/sphinx-gallery/sphinx-gallery/archive/master.zip
Expand Down

0 comments on commit e63190c

Please sign in to comment.