File tree 1 file changed +17
-3
lines changed 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change 1
- import importlib
1
+ from subprocess import check_output , STDOUT , CalledProcessError
2
+ import sys
2
3
import pytest
3
4
import glob
4
5
@@ -23,5 +24,18 @@ def test_run_file(file_path):
23
24
if 'pytorch_fairseq_roberta' in file_path :
24
25
pytest .skip ("temporarily disabled" )
25
26
26
- module = file_path [:- 3 ].replace ('/' , '.' ) # :-3 to remove the .py extension
27
- importlib .import_module (module )
27
+ # We just run the python files in a separate sub-process. We really want a
28
+ # subprocess here because otherwise we might run into package versions
29
+ # issues: imagine script A that needs torchvivion 0.9 and script B that
30
+ # needs torchvision 0.10. If script A is run prior to script B in the same
31
+ # process, script B will still be run with torchvision 0.9 because the only
32
+ # "import torchvision" statement that counts is the first one, and even
33
+ # torchub sys.path shenanigans can do nothing about this. By creating
34
+ # subprocesses we're sure that all file executions are fully independent.
35
+ try :
36
+ # This is inspired (and heavily simplified) from
37
+ # https://github.com/cloudpipe/cloudpickle/blob/343da119685f622da2d1658ef7b3e2516a01817f/tests/testutils.py#L177
38
+ out = check_output ([sys .executable , file_path ], stderr = STDOUT )
39
+ print (out .decode ())
40
+ except CalledProcessError as e :
41
+ raise RuntimeError (f"Script { file_path } errored with output:\n { e .output .decode ()} " )
You can’t perform that action at this time.
0 commit comments