aboutsummaryrefslogtreecommitdiffstats
path: root/conftest.py
diff options
context:
space:
mode:
Diffstat (limited to 'conftest.py')
-rw-r--r--conftest.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/conftest.py b/conftest.py
new file mode 100644
index 0000000..2176354
--- /dev/null
+++ b/conftest.py
@@ -0,0 +1,32 @@
+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'<LAVA_SIGNAL_STARTTC {test_name}>')
+ elif report.when == 'call':
+ test_result = lava_result_convert(report.outcome)
+ print('\n')
+ print(f'<LAVA_SIGNAL_ENDTC {test_name}>')
+ print(f'<LAVA_SIGNAL_TESTCASE TEST_CASE_ID={test_name} RESULT={test_result}>')