import pytest def pytest_addoption(parser): parser.addoption('-L', '--lava', action='store_true', help='enable LAVA signals') def lava_result_convert(pytest_outcome): """ Convert the pytestoutcome to the string expected by LAVA.""" if pytest_outcome == 'passed': return 'pass' elif pytest_outcome == 'skipped': return 'pass' elif pytest_outcome == 'xfailed': return 'pass' else: return'fail' def pytest_report_teststatus(config, report): """ Insert strings that LAVA expects to capture test results.""" # Get pytest test name and remove the 'test_' prefix if config.getoption('--lava'): test_name = report.location[2][5:] if report.when == 'setup': print('\n') print(f'') elif report.when == 'call': test_result = lava_result_convert(report.outcome) print('\n') print(f'') print(f'')