Skip to content

Commit cb6fed0

Browse files
authored
gh-138709: Supress stdout/stderr during test_sampling_profiler tests (#139212)
1 parent 9df477c commit cb6fed0

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Lib/test/test_profiling/test_sampling_profiler.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from test.support import force_not_colorized_test_class, SHORT_TIMEOUT
2323
from test.support.socket_helper import find_unused_port
2424
from test.support import requires_subprocess, is_emscripten
25+
from test.support import captured_stdout, captured_stderr
2526

2627
PROCESS_VM_READV_SUPPORTED = False
2728

@@ -416,7 +417,8 @@ def test_collapsed_stack_collector_export(self):
416417
collector.collect(test_frames2)
417418
collector.collect(test_frames3)
418419

419-
collector.export(collapsed_out.name)
420+
with (captured_stdout(), captured_stderr()):
421+
collector.export(collapsed_out.name)
420422
# Check file contents
421423
with open(collapsed_out.name, "r") as f:
422424
content = f.read()
@@ -500,7 +502,8 @@ def test_flamegraph_collector_export(self):
500502
collector.collect(test_frames3)
501503

502504
# Export flamegraph
503-
collector.export(flamegraph_out.name)
505+
with (captured_stdout(), captured_stderr()):
506+
collector.export(flamegraph_out.name)
504507

505508
# Verify file was created and contains valid data
506509
self.assertTrue(os.path.exists(flamegraph_out.name))
@@ -1918,7 +1921,7 @@ def test_valid_output_formats(self):
19181921
self.addCleanup(shutil.rmtree, tempdir.name)
19191922

19201923

1921-
with contextlib.chdir(tempdir.name):
1924+
with (contextlib.chdir(tempdir.name), captured_stdout(), captured_stderr()):
19221925
for fmt in valid_formats:
19231926
try:
19241927
# This will likely fail with permissions, but the format should be valid
@@ -2632,6 +2635,7 @@ def test_gil_mode_collector_configuration(self):
26322635
with (
26332636
mock.patch("profiling.sampling.sample.SampleProfiler") as mock_profiler,
26342637
mock.patch("profiling.sampling.sample.PstatsCollector") as mock_collector,
2638+
captured_stdout(), captured_stderr()
26352639
):
26362640
# Mock the profiler instance
26372641
mock_instance = mock.Mock()

0 commit comments

Comments
 (0)