Skip to content

Commit d92af80

Browse files
Use configuration.debug=True to enable debug logs in client (#245)
1 parent 6ca1556 commit d92af80

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

clients/python/test/e2e/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from pydantic import ByteSize
2020
from typing import NamedTuple, Final
2121
from memory_profiler import memory_usage
22-
import http.client
2322

2423

2524
try:
@@ -102,9 +101,9 @@ def pytest_configure(config):
102101

103102
@pytest.fixture(scope="session")
104103
def api_client() -> Iterable[osparc.ApiClient]:
105-
http.client.HTTPConnection.debuglevel = 1
106104
if Version(osparc.__version__) >= Version("0.8.0"):
107105
with osparc.ApiClient() as api_client:
106+
api_client.configuration.debug = True
108107
yield api_client
109108
else:
110109
host = os.environ.get("OSPARC_API_HOST")
@@ -114,6 +113,7 @@ def api_client() -> Iterable[osparc.ApiClient]:
114113
configuration = osparc.Configuration(
115114
host=host, username=username, password=password
116115
)
116+
configuration.debug = True
117117
with osparc.ApiClient(configuration=configuration) as api_client:
118118
yield api_client
119119

clients/python/test/e2e/test_notebooks.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@
2020
from rich.panel import Panel
2121

2222
_HTTP_LOGGING_SETUP_CODE: Final[str] = """
23-
# Injected by test runner to enable HTTP request logging
24-
import http.client
25-
http.client.HTTPConnection.debuglevel = 1
26-
27-
import logging
28-
logging.getLogger("osparc").setLevel(logging.DEBUG)
23+
# Injected by test runner: force debug=True on every osparc_client Configuration
24+
import osparc_client
25+
_orig_init = osparc_client.Configuration.__init__
26+
def _init_with_debug(self, *a, **kw):
27+
_orig_init(self, *a, **kw)
28+
self.debug = True
29+
osparc_client.Configuration.__init__ = _init_with_debug
2930
"""
3031

3132
_NOTEBOOK_EXECUTION_TIMEOUT_SECONDS: Final[int] = 60 * 20 # 20min
@@ -54,7 +55,10 @@ def _pretty_print_cell_outputs(notebook_path: Path) -> None:
5455

5556

5657
def _inject_http_logging_setup_cell(notebook_path: Path) -> None:
57-
# Inject HTTP logging setup cell at the beginning of the notebook to ensure osparc http request data is logged (mainly to log trace ids for easier debugging of test failures)
58+
# Inject HTTP logging setup cell at the beginning of the notebook to ensure
59+
# osparc http request data is logged (mainly to log trace ids for easier
60+
# debugging of test failures). Uses a spy on osparc_client.rest to print
61+
# response headers for every HTTP request.
5862
nb = nbformat.read(notebook_path, as_version=4)
5963
setup_cell = nbformat.v4.new_code_cell(source=_HTTP_LOGGING_SETUP_CODE)
6064
nb.cells.insert(0, setup_cell)

0 commit comments

Comments
 (0)