def pytest_terminal_summary(terminalreporter): """Group benchmark results on CI.""" if testutils.ON_CI: terminalreporter.write_line( testutils.gha_group_begin('Benchmark results')) yield terminalreporter.write_line(testutils.gha_group_end()) else: yield
def _render_log(data, *, verbose, threshold=100): """Shorten the given log without -v and convert to a string.""" data = [str(d) for d in data] is_exception = any('Traceback (most recent call last):' in line or 'Uncaught exception' in line for line in data) if (len(data) > threshold and not verbose and not is_exception and not testutils.ON_CI): msg = '[{} lines suppressed, use -v to show]'.format( len(data) - threshold) data = [msg] + data[-threshold:] if testutils.ON_CI: data = [testutils.gha_group_begin('Log') ] + data + [testutils.gha_group_end()] return '\n'.join(data)
def pytest_runtest_makereport(item, call): """Add a BDD section to the test output.""" outcome = yield if call.when not in ['call', 'teardown']: return report = outcome.get_result() if report.passed: return if (not hasattr(report.longrepr, 'addsection') or not hasattr(report, 'scenario')): # In some conditions (on macOS and Windows it seems), report.longrepr # is actually a tuple. This is handled similarly in pytest-qt too. # # Since this hook is invoked for any test, we also need to skip it for # non-BDD ones. return if ((sys.stdout.isatty() or testutils.ON_CI) and item.config.getoption('--color') != 'no'): colors = { 'failed': log.COLOR_ESCAPES['red'], 'passed': log.COLOR_ESCAPES['green'], 'keyword': log.COLOR_ESCAPES['cyan'], 'reset': log.RESET_ESCAPE, } else: colors = { 'failed': '', 'passed': '', 'keyword': '', 'reset': '', } output = [] if testutils.ON_CI: output.append(testutils.gha_group_begin('Scenario')) output.append("{kw_color}Feature:{reset} {name}".format( kw_color=colors['keyword'], name=report.scenario['feature']['name'], reset=colors['reset'], )) output.append( " {kw_color}Scenario:{reset} {name} ({filename}:{line})".format( kw_color=colors['keyword'], name=report.scenario['name'], filename=report.scenario['feature']['rel_filename'], line=report.scenario['line_number'], reset=colors['reset'])) for step in report.scenario['steps']: output.append( " {kw_color}{keyword}{reset} {color}{name}{reset} " "({duration:.2f}s)".format( kw_color=colors['keyword'], color=colors['failed'] if step['failed'] else colors['passed'], keyword=step['keyword'], name=step['name'], duration=step['duration'], reset=colors['reset'])) if testutils.ON_CI: output.append(testutils.gha_group_end()) report.longrepr.addsection("BDD scenario", '\n'.join(output))