|
2 | 2 | # and/or modify it under the terms of the GPL licence |
3 | 3 |
|
4 | 4 | import logging |
5 | | -import cgi |
6 | | - |
7 | | -import pytest |
8 | 5 |
|
9 | 6 | from .service import PyTestService |
10 | | - |
11 | | - |
12 | | -class RP_Report_Listener(object): |
13 | | - |
14 | | - # Identifier if TestItem is called: |
15 | | - # if setup is failed, pytest will NOT call |
16 | | - # TestItem and Result will not reported! |
17 | | - called = None |
18 | | - # Test Item result |
19 | | - result = None |
20 | | - |
21 | | - @pytest.mark.hookwrapper |
22 | | - def pytest_runtest_makereport(self, item, call): |
23 | | - report = (yield).get_result() |
24 | | - |
25 | | - if report.when == "setup": |
26 | | - # when function pytest_setup is called, |
27 | | - # test item session will be started in RP |
28 | | - PyTestService.start_pytest_item(item) |
29 | | - |
30 | | - if report.longrepr: |
31 | | - PyTestService.post_log( |
32 | | - cgi.escape(report.longreprtext), |
33 | | - loglevel='ERROR', |
34 | | - ) |
35 | | - |
36 | | - if report.when == "call": |
37 | | - self.called = True |
38 | | - if report.passed: |
39 | | - item_result = "PASSED" |
40 | | - elif report.failed: |
41 | | - item_result = "FAILED" |
42 | | - else: |
43 | | - item_result = "SKIPPED" |
44 | | - |
45 | | - self.result = item_result |
46 | | - |
47 | | - if report.when == "teardown": |
48 | | - # If item is called, result of TestItem is reported |
49 | | - if self.called is True: |
50 | | - item_result = self.result |
51 | | - else: |
52 | | - # If setup - failed or skipped, |
53 | | - # the TestItem will reported as SKIPPED |
54 | | - item_result = "SKIPPED" |
55 | | - PyTestService.finish_pytest_item(item_result) |
56 | | - self.called = None |
| 7 | +from .listener import RPReportListener |
57 | 8 |
|
58 | 9 |
|
59 | 10 | def pytest_sessionstart(session): |
60 | 11 | PyTestService.init_service( |
61 | | - project=session.config.getini("rp_project"), |
62 | | - endpoint=session.config.getini("rp_endpoint"), |
63 | | - uuid=session.config.getini("rp_uuid"), |
64 | | - log_batch_size=int(session.config.getini("rp_log_batch_size")), |
65 | | - ignore_errors=bool(session.config.getini("rp_ignore_errors")), |
66 | | - ignored_tags=session.config.getini("rp_ignore_tags"), |
| 12 | + project=session.config.getini('rp_project'), |
| 13 | + endpoint=session.config.getini('rp_endpoint'), |
| 14 | + uuid=session.config.getini('rp_uuid'), |
| 15 | + log_batch_size=int(session.config.getini('rp_log_batch_size')), |
| 16 | + ignore_errors=bool(session.config.getini('rp_ignore_errors')), |
| 17 | + ignored_tags=session.config.getini('rp_ignore_tags'), |
67 | 18 | ) |
68 | 19 |
|
69 | 20 | PyTestService.start_launch( |
70 | 21 | session.config.option.rp_launch, |
71 | | - tags=session.config.getini("rp_launch_tags"), |
72 | | - description=session.config.getini("rp_launch_description"), |
| 22 | + tags=session.config.getini('rp_launch_tags'), |
| 23 | + description=session.config.getini('rp_launch_description'), |
73 | 24 | ) |
74 | 25 |
|
75 | 26 |
|
76 | | -def pytest_sessionfinish(session): |
| 27 | +def pytest_sessionfinish(): |
77 | 28 | # FixMe: currently method of RP api takes the string parameter |
78 | 29 | # so it is hardcoded |
79 | | - PyTestService.finish_launch(status="RP_Launch") |
| 30 | + PyTestService.finish_launch(status='RP_Launch') |
80 | 31 |
|
81 | 32 |
|
82 | 33 | def pytest_configure(config): |
83 | 34 | if not config.option.rp_launch: |
84 | | - config.option.rp_launch = config.getini("rp_launch") |
| 35 | + config.option.rp_launch = config.getini('rp_launch') |
85 | 36 |
|
86 | 37 | # set Pytest_Reporter and configure it |
87 | | - config._reporter = RP_Report_Listener() |
| 38 | + config._reporter = RPReportListener() |
88 | 39 |
|
89 | | - if hasattr(config, "_reporter"): |
| 40 | + if hasattr(config, '_reporter'): |
90 | 41 | config.pluginmanager.register(config._reporter) |
91 | 42 |
|
92 | 43 |
|
93 | 44 | def pytest_unconfigure(config): |
94 | 45 | PyTestService.terminate_service() |
95 | 46 |
|
96 | | - if hasattr(config, "_reporter"): |
| 47 | + if hasattr(config, '_reporter'): |
97 | 48 | reporter = config._reporter |
98 | 49 | del config._reporter |
99 | 50 | config.pluginmanager.unregister(reporter) |
100 | | - logging.debug("RP is unconfigured") |
| 51 | + logging.debug('RP is unconfigured') |
101 | 52 |
|
102 | 53 |
|
103 | 54 | def pytest_addoption(parser): |
104 | | - group = parser.getgroup("reporting") |
| 55 | + group = parser.getgroup('reporting') |
105 | 56 | group.addoption( |
106 | | - "--rp-launch", |
107 | | - action="store", |
108 | | - dest="rp_launch", |
109 | | - help="Launch name (overrides rp_launch config option)") |
| 57 | + '--rp-launch', |
| 58 | + action='store', |
| 59 | + dest='rp_launch', |
| 60 | + help='Launch name (overrides rp_launch config option)') |
110 | 61 |
|
111 | 62 | parser.addini( |
112 | | - "rp_uuid", |
113 | | - help="UUID") |
| 63 | + 'rp_uuid', |
| 64 | + help='UUID') |
114 | 65 |
|
115 | 66 | parser.addini( |
116 | | - "rp_endpoint", |
117 | | - help="Server endpoint") |
| 67 | + 'rp_endpoint', |
| 68 | + help='Server endpoint') |
118 | 69 |
|
119 | 70 | parser.addini( |
120 | | - "rp_project", |
121 | | - help="Project name") |
| 71 | + 'rp_project', |
| 72 | + help='Project name') |
122 | 73 |
|
123 | 74 | parser.addini( |
124 | | - "rp_launch", |
125 | | - default="Pytest Launch", |
126 | | - help="Launch name") |
| 75 | + 'rp_launch', |
| 76 | + default='Pytest Launch', |
| 77 | + help='Launch name') |
127 | 78 |
|
128 | 79 | parser.addini( |
129 | | - "rp_launch_tags", |
130 | | - type="args", |
131 | | - help="Launch tags, i.e Performance Regression") |
| 80 | + 'rp_launch_tags', |
| 81 | + type='args', |
| 82 | + help='Launch tags, i.e Performance Regression') |
132 | 83 |
|
133 | 84 | parser.addini( |
134 | | - "rp_launch_description", |
135 | | - default="", |
136 | | - help="Launch description") |
| 85 | + 'rp_launch_description', |
| 86 | + default='', |
| 87 | + help='Launch description') |
137 | 88 |
|
138 | 89 | parser.addini( |
139 | | - "rp_log_batch_size", |
140 | | - default="20", |
141 | | - help="Size of batch log requests in async mode") |
| 90 | + 'rp_log_batch_size', |
| 91 | + default='20', |
| 92 | + help='Size of batch log requests in async mode') |
142 | 93 |
|
143 | 94 | parser.addini( |
144 | | - "rp_ignore_errors", |
| 95 | + 'rp_ignore_errors', |
145 | 96 | default=False, |
146 | | - type="bool", |
147 | | - help="Ignore Report Portal errors (exit otherwise)") |
| 97 | + type='bool', |
| 98 | + help='Ignore Report Portal errors (exit otherwise)') |
148 | 99 |
|
149 | 100 | parser.addini( |
150 | | - "rp_ignore_tags", |
151 | | - type="args", |
152 | | - help="Ignore specified pytest markers, i.e parametrize") |
| 101 | + 'rp_ignore_tags', |
| 102 | + type='args', |
| 103 | + help='Ignore specified pytest markers, i.e parametrize') |
0 commit comments