Skip to content

Commit

Permalink
[test/profiler] Make test_profiler_pattern_matcher_json_report write …
Browse files Browse the repository at this point in the history
…torchtidy_report.json to a tmpdir instead of CWD
  • Loading branch information
kiukchung committed Aug 8, 2024
1 parent 9d5c85c commit 92f7330
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions test/profiler/test_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import struct
import subprocess
import sys
import tempfile
import threading
import time
import unittest
Expand Down Expand Up @@ -2528,9 +2529,11 @@ def test_profiler_pattern_matcher_json_report(self):
loss.backward()
optimizer.step()
optimizer.zero_grad()
report_all_anti_patterns(prof, json_report_dir=".", print_enable=False)
try:
with open("./torchtidy_report.json") as f:

with tempfile.TemporaryDirectory() as tmpdir:
report_all_anti_patterns(prof, json_report_dir=tmpdir, print_enable=False)

with open(os.path.join(tmpdir, "torchtidy_report.json")) as f:
report = json.load(f)

# It is platform dependent whether the path will include "profiler/"
Expand All @@ -2543,8 +2546,6 @@ def test_profiler_pattern_matcher_json_report(self):
for event in entry:
actual_fields = sorted(event.keys())
self.assertEqual(expected_fields, actual_fields)
finally:
os.remove("torchtidy_report.json")

@unittest.skipIf(IS_ARM64 or not IS_LINUX, "x86 linux only cpp unwinding")
def test_fuzz_symbolize(self):
Expand Down

0 comments on commit 92f7330

Please sign in to comment.