Skip to content

Commit 0190885

Browse files
committed
Print and flush
1 parent 22786f4 commit 0190885

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/pytest_ansible_network_integration/__init__.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@ def _github_action_log(message: str) -> None:
196196
print(f"\n{message}", flush=True)
197197

198198

199+
def _print(message: str) -> None:
200+
"""Print a message and flush.
201+
202+
This ensures the message doesn't get buffered and mixed in the test stdout
203+
204+
:param message: The message
205+
"""
206+
print(f"\n{message}", flush=True)
207+
208+
199209
@pytest.fixture(scope="session", name="appliance_dhcp_address")
200210
def _appliance_dhcp_address(env_vars: Dict[str, str]) -> Generator[str, None, None]:
201211
"""Build the lab and collect the appliance DHCP address.
@@ -206,7 +216,7 @@ def _appliance_dhcp_address(env_vars: Dict[str, str]) -> Generator[str, None, No
206216
"""
207217
_github_action_log("::group::Starting lab provisioning")
208218

209-
logger.info("Starting lab provisioning")
219+
_print("Starting lab provisioning")
210220

211221
try:
212222

@@ -240,7 +250,7 @@ def _appliance_dhcp_address(env_vars: Dict[str, str]) -> Generator[str, None, No
240250
raise Exception("Failed to get DHCP lease for the appliance") from exc
241251

242252
end = time.time()
243-
logger.info("Elapsed time to provision %s seconds", end - start)
253+
_print(f"Elapsed time to provision {end - start} seconds")
244254

245255
except Exception as exc:
246256
logger.error("Failed to provision lab")
@@ -293,8 +303,8 @@ def ansible_project(
293303
playbook_path = tmp_path / "site.json"
294304
with playbook_path.open(mode="w", encoding="utf-8") as fh:
295305
json.dump(playbook_contents, fh)
296-
logger.info("Inventory path: %s", inventory_path)
297-
logger.info("Playbook path: %s", playbook_path)
306+
_print(f"Inventory path: {inventory_path}")
307+
_print(f"Playbook path: {playbook_path}")
298308

299309
return AnsibleProject(
300310
playbook=playbook_path,

0 commit comments

Comments
 (0)