Skip to content

Commit 12459b7

Browse files
committed
fixup! Add HTML flamegraph to sampling profiler
1 parent 0803b28 commit 12459b7

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
@@ -1825,18 +1825,23 @@ def test_valid_output_formats(self):
18251825
"""Test that all valid output formats are accepted."""
18261826
valid_formats = ["pstats", "collapsed", "flamegraph"]
18271827

1828-
for fmt in valid_formats:
1829-
try:
1830-
# This will likely fail with permissions, but the format should be valid
1831-
profiling.sampling.sample.sample(
1832-
os.getpid(),
1833-
duration_sec=0.1,
1834-
output_format=fmt,
1835-
filename=f"test_{fmt}.out",
1836-
)
1837-
except (OSError, RuntimeError, PermissionError):
1838-
# Expected errors - we just want to test format validation
1839-
pass
1828+
tempdir = tempfile.TemporaryDirectory(delete=False)
1829+
self.addCleanup(lambda x: shutil.rmtree(x), tempdir.name)
1830+
1831+
1832+
with contextlib.chdir(tempdir.name):
1833+
for fmt in valid_formats:
1834+
try:
1835+
# This will likely fail with permissions, but the format should be valid
1836+
profiling.sampling.sample.sample(
1837+
os.getpid(),
1838+
duration_sec=0.1,
1839+
output_format=fmt,
1840+
filename=f"test_{fmt}.out",
1841+
)
1842+
except (OSError, RuntimeError, PermissionError):
1843+
# Expected errors - we just want to test format validation
1844+
pass
18401845

18411846

18421847
class TestSampleProfilerCLI(unittest.TestCase):

0 commit comments

Comments
 (0)