/
__init__.py
52 lines (43 loc) · 1.31 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""
A simple pytest plugin which collects test information and prints it at the end
of the tests
"""
from collections import defaultdict
import pytest
from ._version import get_versions
__version__ = get_versions()['version']
del get_versions
class InfoCollector:
"""
Main driver of test information collection
"""
def __init__(self):
self._info = defaultdict(list)
def pytest_terminal_summary(self, terminalreporter, exitstatus):
"""
Hook for printing test info at the end of the run
"""
# pylint: disable=unused-argument
terminalreporter.section("Test Information")
for test, info in self._info.items():
for datum in info:
terminalreporter.write("{}: {}\n".format(test, datum))
@pytest.fixture
def test_info(self, request):
"""
Fixture to collect test information
"""
def add_info(info):
"""
Adds information about test
"""
self._info[get_test_name(request)].append(info)
return add_info
def get_test_name(request):
"""
Get the name of test from pytest
"""
return request.node.name
def pytest_configure(config):
"""Add plugin to pytest"""
config.pluginmanager.register(InfoCollector(), "info_collector")