Skip to content

Commit a2aa978

Browse files
committed
Test for caplog utils
Signed-off-by: Luka Govedič <lgovedic@redhat.com>
1 parent eb899a4 commit a2aa978

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ def caplog_vllm(temporary_enable_log_propagate, caplog):
10701070
yield caplog
10711071

10721072

1073-
@pytest.fixture(scope="session")
1073+
@pytest.fixture()
10741074
def caplog_mp_fork():
10751075
"""
10761076
This fixture enables capturing logs from a forked MP subprocess.
@@ -1115,7 +1115,7 @@ def __init__(self):
11151115
self.text = None
11161116

11171117

1118-
@pytest.fixture(scope="session")
1118+
@pytest.fixture()
11191119
def caplog_mp_spawn(tmp_path, monkeypatch):
11201120
"""
11211121
This fixture enables capturing logs from a forked MP subprocess.

tests/test_logger.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,5 +515,34 @@ def mp_function(**kwargs):
515515

516516

517517
def test_caplog_mp_fork(caplog_vllm, caplog_mp_fork):
518-
pass
519-
# TODO
518+
with caplog_vllm.at_level(logging.DEBUG), caplog_mp_fork():
519+
import multiprocessing
520+
521+
ctx = multiprocessing.get_context("fork")
522+
p = ctx.Process(
523+
target=mp_function,
524+
name=f"SubProcess{1}",
525+
kwargs={"a": "AAAA", "b": "BBBBB"},
526+
)
527+
p.start()
528+
p.join()
529+
530+
assert "AAAA" in caplog_vllm.text
531+
assert "BBBBB" in caplog_vllm.text
532+
533+
534+
def test_caplog_mp_spawn(caplog_mp_spawn):
535+
with caplog_mp_spawn(logging.DEBUG) as log_holder:
536+
import multiprocessing
537+
538+
ctx = multiprocessing.get_context("spawn")
539+
p = ctx.Process(
540+
target=mp_function,
541+
name=f"SubProcess{1}",
542+
kwargs={"a": "AAAA", "b": "BBBBB"},
543+
)
544+
p.start()
545+
p.join()
546+
547+
assert "AAAA" in log_holder.text
548+
assert "BBBBB" in log_holder.text

0 commit comments

Comments
 (0)