Skip to content

Commit e1c56ee

Browse files
committed
fixup! Add HTML flamegraph to sampling profiler
1 parent a9b1213 commit e1c56ee

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

Lib/test/test_profiling/test_sampling_profiler.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,18 +1900,23 @@ def test_valid_output_formats(self):
19001900
"""Test that all valid output formats are accepted."""
19011901
valid_formats = ["pstats", "collapsed", "flamegraph"]
19021902

1903-
for fmt in valid_formats:
1904-
try:
1905-
# This will likely fail with permissions, but the format should be valid
1906-
profiling.sampling.sample.sample(
1907-
os.getpid(),
1908-
duration_sec=0.1,
1909-
output_format=fmt,
1910-
filename=f"test_{fmt}.out",
1911-
)
1912-
except (OSError, RuntimeError, PermissionError):
1913-
# Expected errors - we just want to test format validation
1914-
pass
1903+
tempdir = tempfile.TemporaryDirectory(delete=False)
1904+
self.addCleanup(lambda x: shutil.rmtree(x), tempdir.name)
1905+
1906+
1907+
with contextlib.chdir(tempdir.name):
1908+
for fmt in valid_formats:
1909+
try:
1910+
# This will likely fail with permissions, but the format should be valid
1911+
profiling.sampling.sample.sample(
1912+
os.getpid(),
1913+
duration_sec=0.1,
1914+
output_format=fmt,
1915+
filename=f"test_{fmt}.out",
1916+
)
1917+
except (OSError, RuntimeError, PermissionError):
1918+
# Expected errors - we just want to test format validation
1919+
pass
19151920

19161921

19171922
class TestSampleProfilerCLI(unittest.TestCase):

0 commit comments

Comments
 (0)