33import os
44
55import subprocess
6- import tempfile
76import unittest
87
98from torch .testing ._internal .common_utils import (
109 IS_WINDOWS ,
1110 run_tests ,
1211 slowTest ,
12+ TemporaryFileName ,
1313 TestCase ,
1414)
1515
@@ -23,33 +23,30 @@ def _test_runner(self, model, disable_gpu=False):
2323 # The temporary file is exclusively open by this process and the child process
2424 # is not allowed to open it again. As this is a simple smoke test, we choose for now
2525 # not to run this on windows and keep the code here simple.
26- with tempfile . NamedTemporaryFile () as out_file :
26+ with TemporaryFileName () as out_file :
2727 cmd = [
2828 "python3" ,
2929 "../benchmarks/functional_autograd_benchmark/functional_autograd_benchmark.py" ,
3030 ]
31+ if IS_WINDOWS :
32+ cmd [0 ] = "python"
3133 # Only run the warmup
3234 cmd += ["--num-iters" , "0" ]
3335 # Only run the vjp task (fastest one)
3436 cmd += ["--task-filter" , "vjp" ]
3537 # Only run the specified model
3638 cmd += ["--model-filter" , model ]
3739 # Output file
38- cmd += ["--output" , out_file . name ]
40+ cmd += ["--output" , out_file ]
3941 if disable_gpu :
4042 cmd += ["--gpu" , "-1" ]
4143
42- res = subprocess .run (cmd )
44+ res = subprocess .run (cmd , check = False )
4345
4446 self .assertTrue (res .returncode == 0 )
4547 # Check that something was written to the file
46- out_file .seek (0 , os .SEEK_END )
47- self .assertTrue (out_file .tell () > 0 )
48+ self .assertTrue (os .stat (out_file ).st_size > 0 )
4849
49- @unittest .skipIf (
50- IS_WINDOWS ,
51- "NamedTemporaryFile on windows does not have all the features we need." ,
52- )
5350 @unittest .skipIf (
5451 PYTORCH_COLLECT_COVERAGE ,
5552 "Can deadlocks with gcov, see https://github.com/pytorch/pytorch/issues/49656" ,
0 commit comments