Skip to content

Commit

Permalink
Store test data with report (#84)
Browse files Browse the repository at this point in the history
* storing logs

* pytest-reportlog

* output captured stdout

* copy itf trace to report dir

* separate method
  • Loading branch information
rnbguy committed Aug 26, 2022
1 parent f93e1b2 commit 8da1cb3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
7 changes: 6 additions & 1 deletion atomkraft/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ def RequiredFileOption(help, default):
def trace(
# currently, require the trace to be present.
# later, there will be an option to pick up the last one from the model
verbose: bool = typer.Option(
False, "--verbose", "-v", help="Output logging on console"
),
trace: typer.FileText = RequiredFileOption("trace to execute", "model"),
reactor: typer.FileText = FileOption("reactor to interpret the trace", "reactor"),
keypath: str = typer.Option(
Expand All @@ -39,7 +42,9 @@ def trace(
Test blockchain by running one trace
"""

test_trace(trace.name, reactor if reactor is None else reactor.name, keypath)
test_trace(
trace.name, reactor if reactor is None else reactor.name, keypath, verbose
)


@app.command()
Expand Down
37 changes: 35 additions & 2 deletions atomkraft/test/trace.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import os.path
import shutil
from datetime import datetime
from os import PathLike
from pathlib import Path
from typing import List

import pytest
from atomkraft.utils.project import project_root
Expand All @@ -18,7 +21,15 @@ def test_trace():
"""


def test_trace(trace: PathLike, reactor: PathLike, keypath: str):
def copy(src_paths: List[Path], dst_path: Path):
for src in src_paths:
if src.is_dir():
shutil.copytree(src, dst_path / src.name)
else:
shutil.copy2(src, dst_path)


def test_trace(trace: PathLike, reactor: PathLike, keypath: str, verbose: bool):
"""
Test blockchain by running one trace
"""
Expand Down Expand Up @@ -52,4 +63,26 @@ def test_trace(trace: PathLike, reactor: PathLike, keypath: str):
)
)
print(f"Executing {test_name} ...")
pytest.main(["-s", test_path])

report_dir = root / "reports" / test_name
report_dir.mkdir(parents=True)

logging_file = report_dir / "log.txt"

pytest_report_file = report_dir / "report.jsonl"

pytest_args = [
"--log-file-level=INFO",
f"--log-file={logging_file}",
f"--report-log={pytest_report_file}",
]

if verbose:
pytest_args.append("-rP")
pytest_args.append("--log-cli-level=INFO")

pytest.main(pytest_args + [test_path])

copy([Path(trace), root / ".atomkraft" / "nodes"], report_dir)

print(f"Test data is saved at {report_dir}")
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ websockets = "^10.3"
GitPython = "^3.1.27"
tomlkit = "^0.11.1"
case-converter = "^1.1.0"
pytest-reportlog = "^0.1.2"

[build-system]
requires = ["poetry-core>=1.0.0", "setuptools>=42"]
Expand Down

0 comments on commit 8da1cb3

Please sign in to comment.