Skip to content

Commit aa02d36

Browse files
refactor(allure): edit tasks to a better allure report generation
1 parent 25c217a commit aa02d36

File tree

4 files changed

+63
-15
lines changed

4 files changed

+63
-15
lines changed

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ plugins:
2727

2828
nav:
2929
- 'Home': index.md
30+
- 'Test Report': 'test-report/allure/'
3031
- 'API Reference':
3132
- 'Bash Utilities':
3233
- 'Alerts': api/bash/alerts.md

pyproject.toml

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -124,25 +124,43 @@ pythonpath = [
124124
addopts = "--doctest-modules"
125125

126126
[tool.taskipy.tasks]
127-
# LINTING
127+
# MAIN COMMANDS
128+
test = "poetry run task _check && poetry run task _pytest_local"
129+
site = "poetry run task _build_site && echo 'Site built successfully! Run `poetry run task serve` to preview.' || echo 'Site build failed. Run `poetry run task _build_site` for detailed logs.'"
130+
docs = "mkdocs serve"
131+
serve = "python -m http.server --directory site 8008"
132+
133+
# QUALITY CHECKS
128134
lint = "ruff check . && isort --check --diff ."
129-
format = "ruff format . && isort ."
130-
# TYPE CHECKING
131135
typecheck = "mypy ."
132-
# TESTING
133-
pre_test = "task lint && task typecheck"
134-
test = "rm -rf test/allure-results && pytest -s -x --cov=scriptize -vv --alluredir=test/allure-results"
135-
test_ci = "rm -rf test/allure-results && pytest -s --cov=scriptize -vv --alluredir=test/allure-results"
136-
# REPORTS
137-
post_test = "coverage html && cp -r test/allure-report/history test/allure-results/ 2>/dev/null || true && python -c \"import json, time; data={'name': 'Local Build', 'buildName': f'Run @ {time.strftime(\\\"%Y-%m-%d %H:%M:%S\\\")}'}; f=open('test/allure-results/executor.json', 'w'); json.dump(data, f);\" && allure -q generate test/allure-results --clean -o test/allure-report && echo 'Wrote Allure report to test/allure-reports/index.html'"
138-
report_ci = "allure generate test/allure-results --clean -o test/allure-report"
139-
cov_missing = "coverage report -m"
140-
docs = "mkdocs serve"
141-
# CI PIPELINE
142-
ci = "task test_ci"
136+
_check = "poetry run task lint && poetry run task typecheck"
137+
format = "ruff format . && isort ."
138+
post_test = "coverage html"
139+
140+
# CORE TEST
141+
_pytest_local = "rm -rf test/allure-results && pytest -s -x --cov=scriptize -vv --alluredir=test/allure-results"
142+
_pytest_ci = "rm -rf test/allure-results && pytest -s --cov=scriptize -vv --alluredir=test/allure-results"
143+
144+
# CORE BUILD
145+
_docs_build = "mkdocs build --clean"
146+
_report_build = """
147+
mkdir -p test/allure-history && \
148+
cp -r test/allure-history/history test/allure-results/ 2>/dev/null || true && \
149+
python test/scripts/generate_executor.py && \
150+
allure -q generate test/allure-results --clean -o site/test-report/allure && \
151+
cp -r site/test-report/allure/history test/allure-history/
152+
"""
153+
_build_site = """
154+
echo '[1/3] Running tests...' && poetry run task _pytest_local >/dev/null 2>&1 && \
155+
echo '[2/3] Building documentation...' && poetry run task _docs_build >/dev/null 2>&1 && \
156+
echo '[3/3] Building test report...' && poetry run task _report_build >/dev/null 2>&1
157+
"""
158+
159+
# GITHUB CI
160+
ci = "poetry run task _check && poetry run task _pytest_ci"
143161

144162
[tool.coverage.html]
145-
directory = "test/htmlcov"
163+
directory = "site/test-report/coverage"
146164

147165
[tool.coverage.run]
148166
branch = true

test/scripts/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Contains test scripts to help with testing and report generation."""

test/scripts/generate_executor.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""Generates the executor.json metadata file for local Allure reports."""
2+
3+
import json
4+
import time
5+
from pathlib import Path
6+
7+
8+
def create_local_executor() -> None:
9+
"""Creates the executor.json for a local Allure run."""
10+
results_dir = Path("test/allure-results")
11+
if not results_dir.is_dir():
12+
# This print is fine for a helper script.
13+
print("Allure results directory not found, skipping executor.json creation.") # noqa: T201
14+
return
15+
16+
executor_file = results_dir / "executor.json"
17+
data = {
18+
"name": "Local Build",
19+
"buildName": f"Run @ {time.strftime('%Y-%m-%d %H:%M:%S')}",
20+
"type": "local",
21+
}
22+
23+
with executor_file.open("w") as f:
24+
json.dump(data, f)
25+
26+
27+
if __name__ == "__main__":
28+
create_local_executor()

0 commit comments

Comments
 (0)