| from pytest import fixture |
| from playwright.sync_api import sync_playwright |
|
|
| from environment import * |
| from lib.app_runner import AppRunner |
| from lib.page_runner import PageRunner |
| from lib.report import AccuracyReport, DelayReport, LogReport |
| from lib.utils import get_time_str |
|
|
| @fixture(scope="session") |
| def log_file(): |
| if RUN_TYPE == RunType.electron: |
| log_file = APP_LOG |
| elif RUN_TYPE == RunType.code: |
| log_file = CODE_LOG |
| elif RUN_TYPE == RunType.dev: |
| log_file = DEV_LOG |
| else: |
| raise TypeError(f"invalid run_type: {RUN_TYPE}") |
| return log_file |
|
|
| @fixture(scope="session") |
| def app(): |
| app = AppRunner(RUN_TYPE) |
| app.start() |
| yield app |
| app.stop() |
|
|
| @fixture(scope="module") |
| def page(): |
| with sync_playwright() as p: |
| page = PageRunner(RUN_TYPE).start(p) |
| yield page |
|
|
| @fixture(scope="module") |
| def accuracy_report(request): |
| report = AccuracyReport() |
| yield report |
| report.to_csv(REPORTS_DIR/f"accuracy_report_{get_time_str()}.csv") |
|
|
| @fixture(scope="module") |
| def delay_report(request): |
| report = DelayReport() |
| yield report |
| report.to_csv(REPORTS_DIR/f"delay_report_{get_time_str()}.csv") |
|
|
| @fixture(scope="session") |
| def log_report(request): |
| report = LogReport() |
| yield report |
| report.to_csv(REPORTS_DIR/f"log_report_{get_time_str()}.csv") |
|
|
|
|
|
|