Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ venv/

# Local
logs/pytest.log
logs/test_level.log
main.py
reports/*
working/*
Expand Down
41 changes: 40 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import datetime

import pytest
from playwright.sync_api import sync_playwright

from libs import CurrentExecution as ce
from libs import file_ops as fo
from libs.generic_constants import fixture_scope
from libs.generic_constants import audit_log_paths, file_mode, fixture_scope
from libs.mavis_constants import browsers_and_devices, playwright_constants
from libs.wrappers import *

Expand Down Expand Up @@ -88,3 +90,40 @@ def close_browser(browser, page):
page.get_by_role("button", name="Log out").click()
page.close()
browser.close()


@pytest.hookimpl(tryfirst=True)
def pytest_sessionstart(session):
with open(audit_log_paths.TEST_LEVEL_LOG, file_mode.APPEND) as log_file:
log_file.write(f"Test Session Started: {datetime.now()}\n")


@pytest.hookimpl(trylast=True)
def pytest_sessionfinish(session, exitstatus):
with open(audit_log_paths.TEST_LEVEL_LOG, file_mode.APPEND) as log_file:
log_file.write(f"Test Session Ended: {datetime.now()}\n")


@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_logreport(report):
outcome = yield

if report.when == "call": # Log only actual test results
test_name = report.nodeid
test_result = report.outcome.upper() # 'passed', 'failed', or 'skipped'
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

with open(audit_log_paths.TEST_LEVEL_LOG, file_mode.APPEND) as log_file:
log_file.write(f"{timestamp} | {test_name} | {test_result}\n")


# @pytest.fixture
# def step_logger():
# """Fixture to log individual steps within a test."""

# def log_step(step_description):
# timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# with open(audit_log_paths.TEST_LEVEL_LOG, file_mode.APPEND) as log_file:
# log_file.write(f"{timestamp} | STEP | {step_description}\n")

# return log_step
4 changes: 4 additions & 0 deletions libs/generic_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,7 @@ class escape_characters:

class file_encoding:
ASCII: Final[str] = "ascii"


class audit_log_paths:
TEST_LEVEL_LOG: Final[str] = "logs/test_level.log"
Loading