Skip to content
Snippets Groups Projects
Commit 2695da60 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
pytest with LAVA instrumentation
================================
This directory contains a complete example showing how to integrate
pytest with LAVA.
It consists of:
* `lava_plugin.py` - A simple pytest plugin that emits LAVA signals for
each test case
* `pytest-example.yaml` - LAVA test definition used to run the test
* `test_example.py` - A tiny, tiny test suite
#
# 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
#
# qemu_alpine.yaml
#
# Exaple QEMU job
#
---
device_type: "qemu"
job_name: "wget-smoke-test@qemu-arm64"
priority: "medium"
visibility: "public"
context:
arch: "arm64"
machine: "virt"
netdevice: user
cpu: "cortex-a57"
memory: "4G"
extra_options: ["-no-reboot", "-smp 2"]
timeouts:
job: {minutes: 15}
action: {minutes: 10}
connection: {minutes: 10}
actions:
- deploy:
to: tmpfs
timeout: {minutes: 5}
images:
kernel:
url: "http://fileserver/Image.gz"
compression: gz
image_arg: -kernel {kernel} -append 'console=ttyAMA0,38400n8'
initrd:
url: "http://fileserver/alpine-base-latest.cpio.zst"
image_arg: -initrd {initrd}
- boot:
method: qemu
timeout: {minutes: 5}
auto_login:
login_prompt: "login:"
username: "root"
prompts: ["([a-zA-Z0-9@]*):[/~]#"]
- test:
timeout:
minutes: 15
definitions:
- name: wget-smoke-test
from: inline
path: unused.yaml
repository:
metadata:
format: Lava-Test Test Definition 1.0
name: wget-smoke-test
description: "Simple network tests"
run:
steps:
- lava-test-case fetch-index --shell wget http://fileserver
- lava-test-case html-check --shell grep -q '<html' index.html
- rm -f index.html
- lava-test-case fetch-index --shell wget https://google.com
- lava-test-case html-check --shell grep -q '<html' index.html
- rm -f index.html
- lava-test-case fetch-index --shell wget http://does.not.exist
- lava-test-case html-check --shell grep -q '<html' index.html
- rm -f index.html
#!/bin/sh
wget_test () {
f=$(echo $1 | cut -f3 -d/)
lava-test-case fetch-from-$f --shell wget -O $f.html $1
lava-test-case html-check-$f --shell grep -q html $f.html
}
wget_test http://fileserver
wget_test https://google.com
wget_test http://does.not.exist
---
metadata:
name: wget-smoke
format: "Lava-Test-Shell Test Definition 1.0"
description: "Simple network tests"
version: 1.0
run:
steps:
- "(cd wget-smoke; ./wget-smoke.sh)"
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