|
1 | 1 | from __future__ import (absolute_import, division, print_function,
|
2 | 2 | unicode_literals)
|
3 | 3 |
|
| 4 | +from six.moves import reduce |
4 | 5 | import inspect
|
5 | 6 | import os
|
6 | 7 | import pytest
|
@@ -83,17 +84,31 @@ def pytest_configure(config):
|
83 | 84 | ccache.ConversionCache(max_size=int(max_size))
|
84 | 85 | else:
|
85 | 86 | ccache.conversion_cache = ccache.ConversionCache()
|
| 87 | + if config.pluginmanager.hasplugin('xdist'): |
| 88 | + config.pluginmanager.register(DeferPlugin()) |
86 | 89 |
|
87 | 90 |
|
88 | 91 | def pytest_unconfigure(config):
|
89 | 92 | ccache.conversion_cache.expire()
|
90 | 93 | matplotlib._called_from_pytest = False
|
91 | 94 |
|
92 | 95 |
|
| 96 | +def pytest_sessionfinish(session): |
| 97 | + if hasattr(session.config, 'slaveoutput'): |
| 98 | + session.config.slaveoutput['cache-report'] = ccache.conversion_cache.report() |
| 99 | + |
| 100 | + |
93 | 101 | def pytest_terminal_summary(terminalreporter):
|
94 | 102 | tr = terminalreporter
|
95 |
| - data = ccache.conversion_cache.report() |
96 |
| - tr.write_sep('-', 'Image conversion cache report') |
| 103 | + if hasattr(tr.config, 'cache_reports'): |
| 104 | + reports = tr.config.cache_reports |
| 105 | + data = {'hits': reduce(lambda x, y: x.union(y), |
| 106 | + (rep['hits'] for rep in reports)), |
| 107 | + 'gets': reduce(lambda x, y: x.union(y), |
| 108 | + (rep['gets'] for rep in reports))} |
| 109 | + else: |
| 110 | + data = ccache.conversion_cache.report() |
| 111 | + tr.write_sep('=', 'Image conversion cache report') |
97 | 112 | tr.write_line('Hit rate: %d/%d' % (len(data['hits']), len(data['gets'])))
|
98 | 113 | if tr.config.getoption('--conversion-cache-report-misses'):
|
99 | 114 | tr.write_line('Missed files:')
|
@@ -125,3 +140,10 @@ def pytest_pycollect_makeitem(collector, name, obj):
|
125 | 140 | obj.teardown_class = obj.tearDownClass
|
126 | 141 |
|
127 | 142 | return pytest.Class(name, parent=collector)
|
| 143 | + |
| 144 | + |
| 145 | +class DeferPlugin(object): |
| 146 | + def pytest_testnodedown(self, node, error): |
| 147 | + if not hasattr(node.config, 'cache_reports'): |
| 148 | + node.config.cache_reports = [] |
| 149 | + node.config.cache_reports.append(node.slaveoutput['cache-report']) |
0 commit comments