Skip to content

Commit 46edf7b

Browse files
authored
Small PARAMETRIC cleanups (#5761)
1 parent 47ab8bc commit 46edf7b

File tree

4 files changed

+36
-36
lines changed

4 files changed

+36
-36
lines changed

utils/_context/_scenarios/parametric.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -160,26 +160,16 @@ def get_apm_library(
160160
library_env: dict,
161161
library_extra_command_arguments: list[str],
162162
) -> Generator[ParametricTestClientApi, None, None]:
163-
log_path = f"{self.host_log_folder}/outputs/{request.cls.__name__}/{request.node.name}/server_log.log"
164-
Path(log_path).parent.mkdir(parents=True, exist_ok=True)
165-
166-
with (
167-
open(log_path, "w+", encoding="utf-8") as log_file,
168-
self._test_client_factory.get_apm_library(
169-
worker_id=worker_id,
170-
test_id=test_id,
171-
test_agent=test_agent,
172-
library_env=library_env,
173-
library_extra_command_arguments=library_extra_command_arguments,
174-
test_server_log_file=log_file,
175-
) as result,
176-
):
163+
with self._test_client_factory.get_apm_library(
164+
request=request,
165+
worker_id=worker_id,
166+
test_id=test_id,
167+
test_agent=test_agent,
168+
library_env=library_env,
169+
library_extra_command_arguments=library_extra_command_arguments,
170+
) as result:
177171
yield result
178172

179-
request.node.add_report_section(
180-
"teardown", f"{self.library.name.capitalize()} Library Output", f"Log file:\n./{log_path}"
181-
)
182-
183173

184174
def _get_base_directory() -> str:
185175
return str(Path.cwd())

utils/docker_fixtures/_test_clients/_core.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from pathlib import Path
33
import shutil
44
import subprocess
5+
from typing import TextIO
56

67
from docker.models.images import Image
78
import pytest
@@ -110,3 +111,9 @@ def image(self) -> Image:
110111
@property
111112
def command(self) -> list[str]:
112113
return self.image.attrs["Config"]["Cmd"]
114+
115+
def get_client_log_file(self, request: pytest.FixtureRequest) -> TextIO:
116+
log_path = Path(f"{self.host_log_folder}/outputs/{request.cls.__name__}/{request.node.name}/server_log.log")
117+
log_path.parent.mkdir(parents=True, exist_ok=True)
118+
119+
return log_path.open("w+", encoding="utf-8")

utils/docker_fixtures/_test_clients/_test_client_framework_integrations.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from collections.abc import Generator
22
import contextlib
33
from http import HTTPStatus
4-
from pathlib import Path
54
import time
65
import urllib.parse
76

@@ -67,11 +66,8 @@ def get_client(
6766
# overwrite env with the one provided by the test
6867
environment |= library_env
6968

70-
log_path = f"{self.host_log_folder}/outputs/{request.cls.__name__}/{request.node.name}/server_log.log"
71-
Path(log_path).parent.mkdir(parents=True, exist_ok=True)
72-
7369
with (
74-
open(log_path, "w+", encoding="utf-8") as log_file,
70+
self.get_client_log_file(request) as log_file,
7571
docker_run(
7672
image=self.tag,
7773
name=f"{self.container_name}-{test_id}",
@@ -88,7 +84,7 @@ def get_client(
8884
yield client
8985

9086
request.node.add_report_section(
91-
"teardown", f"{self.library.capitalize()} Library Output", f"Log file:\n./{log_path}"
87+
"teardown", f"{self.library.capitalize()} Library Output", f"Log file:\n./{log_file.name}"
9288
)
9389

9490

utils/docker_fixtures/_test_clients/_test_client_parametric.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from http import HTTPStatus
44
import time
55
from types import TracebackType
6-
from typing import TextIO, TypedDict
6+
from typing import TypedDict
77
import urllib.parse
88

99
from _pytest.outcomes import Failed
@@ -31,12 +31,12 @@ class ParametricTestClientFactory(TestClientFactory):
3131
@contextlib.contextmanager
3232
def get_apm_library(
3333
self,
34+
request: pytest.FixtureRequest,
3435
worker_id: str,
3536
test_id: str,
3637
test_agent: TestAgentAPI,
3738
library_env: dict,
3839
library_extra_command_arguments: list[str],
39-
test_server_log_file: TextIO,
4040
) -> Generator["ParametricTestClientApi", None, None]:
4141
host_port = get_host_port(worker_id, 4500)
4242
container_port = 8080
@@ -67,16 +67,19 @@ def get_apm_library(
6767
# temporary workaround for the test server to be able to run the command
6868
env["SYSTEM_TESTS_EXTRA_COMMAND_ARGUMENTS"] = " ".join(library_extra_command_arguments)
6969

70-
with docker_run(
71-
image=self.tag,
72-
name=f"{self.container_name}-{test_id}",
73-
command=command,
74-
env=env,
75-
ports={f"{container_port}/tcp": host_port},
76-
volumes=self.container_volumes,
77-
log_file=test_server_log_file,
78-
network=test_agent.network,
79-
) as container:
70+
with (
71+
self.get_client_log_file(request) as log_file,
72+
docker_run(
73+
image=self.tag,
74+
name=f"{self.container_name}-{test_id}",
75+
command=command,
76+
env=env,
77+
ports={f"{container_port}/tcp": host_port},
78+
volumes=self.container_volumes,
79+
log_file=log_file,
80+
network=test_agent.network,
81+
) as container,
82+
):
8083
test_server_timeout = 60
8184

8285
client = ParametricTestClientApi(
@@ -88,6 +91,10 @@ def get_apm_library(
8891

8992
yield client
9093

94+
request.node.add_report_section(
95+
"teardown", f"{self.library.capitalize()} Library Output", f"Log file:\n./{log_file.name}"
96+
)
97+
9198

9299
def _fail(message: str):
93100
"""Used to mak a test as failed"""

0 commit comments

Comments
 (0)