Skip to content

Commit

Permalink
Cleanup conftest
Browse files Browse the repository at this point in the history
  • Loading branch information
sternakt committed Jan 21, 2025
1 parent 7efc18b commit 9416bc0
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing import Any, Optional

import pytest
from pytest import CallInfo, Item

import autogen

Expand Down Expand Up @@ -119,6 +120,28 @@ def api_key(self) -> str:
return self.llm_config["config_list"][0]["api_key"] # type: ignore[no-any-return]


class CensoredError(Exception):
def __init__(self, exception: BaseException):
self.exception = exception
self.__traceback__ = exception.__traceback__
original_message = "".join([repr(arg) for arg in exception.args])
message = Secrets.sanitize_secrets(original_message)
super().__init__(message)


def pytest_runtest_makereport(item: Item, call: CallInfo[Any]) -> None:
"""
Hook to customize the exception output.
This is called after each test call.
"""
if call.excinfo is not None: # This means the test failed
original_message = "".join([repr(arg) for arg in call.excinfo.value.args])

if Secrets.needs_sanitizing(original_message):
censored_exception = CensoredError(call.excinfo.value)
call.excinfo = pytest.ExceptionInfo.from_exception(censored_exception)


def get_credentials(
filter_dict: Optional[dict[str, Any]] = None, temperature: float = 0.0, fail_if_empty: bool = True
) -> Credentials:
Expand Down Expand Up @@ -286,28 +309,6 @@ def pytest_sessionfinish(session: pytest.Session, exitstatus: int) -> None:
session.exitstatus = 0


class CensoredError(Exception):
def __init__(self, exception: Exception):
self.exception = exception
self.__traceback__ = exception.__traceback__
original_message = "".join([repr(arg) for arg in exception.args])
message = Secrets.sanitize_secrets(original_message)
super().__init__(message)


# def pytest_runtest_makereport(item, call):
# """
# Hook to customize the exception output.
# This is called after each test call.
# """
# if call.excinfo is not None: # This means the test failed
# original_message = "".join([repr(arg) for arg in call.excinfo.value.args])

# if Secrets.needs_sanitizing(original_message):
# censored_exception = CensoredError(call.excinfo.value)
# call.excinfo = pytest.ExceptionInfo.from_exception(censored_exception)


credentials_all_llms = [
pytest.param(
credentials_gpt_4o_mini.__name__,
Expand Down

0 comments on commit 9416bc0

Please sign in to comment.