Module 9 ยท Python for SDETs

Reporting &
suite structure

Make a suite legible to a team โ€” shareable reports, markers, folders

pytest-html markers conftest per area the gate command
AI with Rufat
A single shareable report file
bash
# install once, then re-pin
pip install pytest-html
pip freeze > requirements.txt
pytest --html=report.html \
--self-contained-html
๐Ÿ“„Lists every test โ€” outcome, duration, captured output, failing tracebacks inline.
๐Ÿ“Ž--self-contained-html inlines the CSS/JS, so the one file is emailable or uploadable as a CI artifact.
AI with Rufat
Tag a subset, run just that subset
# pytest.ini
[pytest]
markers =
smoke: fast, critical subset
api: hits the REST API
ui: drives the browser
@pytest.mark.smoke
def test_products_up(): โ€ฆ
pytest -m smoke
pytest -m "api and not smoke"
pytest -m ui
๐Ÿšฆ-m supports and/or/not. A seconds-long smoke subset is your everyday "did we break anything critical?" gate.
AI with Rufat
Group by area, share fixtures by folder
tests/
โ”œโ”€โ”€ conftest.py # shared
โ”œโ”€โ”€ api/
โ”‚ โ”œโ”€โ”€ conftest.py
โ”‚ โ””โ”€โ”€ test_products.py
โ””โ”€โ”€ ui/
โ”œโ”€โ”€ conftest.py
โ””โ”€โ”€ test_login.py
๐Ÿ—‚๏ธpytest loads every conftest.py on the path to a test โ€” no imports.
๐ŸŽฏTop conftest.py = shared fixtures (everywhere); a nested one = scoped to that area. Central shared, local specific.
AI with Rufat
Legible input, legible output

One command: fast subset ยท artifact ยท clean summary

pytest -m smoke --html=smoke-report.html \
--self-contained-html -ra --tb=short
-m smoke fast subset
--html artifact
-ra skips/xfails
--tb=short compact
๐ŸงพAlso handy: --durations=10 (slowest tests) and -q (one char per test). Module 10 wires this exact gate into GitHub Actions.
AI with Rufat
๐Ÿงพ

A suite a
team can read

Shareable reports, a smoke gate, and a folder layout that scales past a dozen files

๐Ÿ“„
Practice
Generate report.html and find a test's duration and outcome
๐Ÿšฆ
Smoke gate
Tag two fast tests and run only pytest -m smoke
โžก๏ธ
Module 10
CI โ€” run the suite on every push with GitHub Actions
AI with Rufat
โ† / โ†’ ยท space