Skip to content
Snippets Groups Projects
Commit df56630c authored by Daniel Thompson's avatar Daniel Thompson
Browse files

Initial pytest example

parents
No related branches found
No related tags found
No related merge requests found
__pycache__
.*.swp
.*.swo
---
extends: default
rules:
line-length: disable
#
# Simple pytest plugin to emit LAVA signals for each test case
#
def lava_result_convert(pytest_outcome):
return 'pass' if pytest_outcome == 'passed' else 'fail'
# When a test fails pytest will call the teststatus hook for a second time
# during the failure reporting summary. We will using this boolean to
# suppress results that aren't emitted between 'setup' and 'teardown'.
running = True
def pytest_report_teststatus(report):
global running
test_name = report.location[2][5:]
if report.when == 'setup':
running = True
print(f'\n<LAVA_SIGNAL_STARTTC {test_name}>')
elif report.when == 'call' and running:
test_result = lava_result_convert(report.outcome)
print(f'\n<LAVA_SIGNAL_ENDTC {test_name}>')
print(f'<LAVA_SIGNAL_TESTCASE TEST_CASE_ID={test_name} RESULT={test_result}>')
elif report.when == 'teardown':
running = False
---
metadata:
name: pytest-example
format: "Lava-Test-Shell Test Definition 1.0"
description: "Demonstrate how to emit LAVA signals from pytest"
version: 1.0
run:
steps:
- "(cd pytest; PYTHONPATH=: pytest --color=no -v -p lava_plugin)"
#
# Trivial test suite with one passing and one failing test
#
def inc(x):
return x + 1
def test_good_answer():
assert inc(3) == 4
def test_bad_answer():
assert inc(3) == 5
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment