Files
cleveragents-core/tests/features/support/env.py
T

71 lines
1.9 KiB
Python

import os
import shutil
import sys
import traceback
from pathlib import Path
# Add the src directory to the path so we can import the package
sys.path.insert(
0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../src"))
)
def before_all(context):
# Set up any global context here
# Add custom exception hook for better error reporting
original_excepthook = sys.excepthook
def custom_excepthook(exc_type, exc_value, exc_traceback):
print("\n\n===== UNCAUGHT EXCEPTION =====")
print(f"Type: {exc_type.__name__}")
print(f"Value: {exc_value}")
print("Traceback:")
traceback.print_tb(exc_traceback)
print("==============================\n")
# Call the original excepthook
original_excepthook(exc_type, exc_value, exc_traceback)
sys.excepthook = custom_excepthook
def after_all(context):
# Clean up after all tests
pass
def before_feature(context, feature):
# Set up context for each feature
pass
def after_feature(context, feature):
# Clean up after each feature
pass
def before_scenario(context, scenario):
# Set up context for each scenario
pass
def after_scenario(context, scenario):
# Clean up after each scenario
# Capture any errors that occurred during the scenario
if scenario.status == "failed":
print(f"\n\n===== SCENARIO FAILED: {scenario.name} =====")
if hasattr(context, "error"):
print(f"Error: {context.error}")
print("===============================\n")
if hasattr(context, "env_patchers"):
for patcher in reversed(context.env_patchers):
patcher.stop()
delattr(context, "env_patchers")
if hasattr(context, "cleanup_dirs"):
for temp_dir in context.cleanup_dirs:
if temp_dir.exists():
shutil.rmtree(temp_dir)
del context.cleanup_dirs