3131import os
3232import re
3333import tempfile
34+ import easybuild .tools .environment as env
3435from distutils .version import LooseVersion
3536from easybuild .easyblocks .generic .pythonpackage import PythonPackage
3637from easybuild .framework .easyconfig import CUSTOM
37- from easybuild .tools .build_log import EasyBuildError
38+ from easybuild .tools .build_log import EasyBuildError , print_warning
3839from easybuild .tools .config import build_option
39- import easybuild .tools .environment as env
40+ from easybuild .tools .filetools import symlink , apply_regex_substitutions
4041from easybuild .tools .modules import get_software_root , get_software_version
4142from easybuild .tools .systemtools import POWER , get_cpu_architecture
42- from easybuild .tools .filetools import symlink , apply_regex_substitutions
43+ from easybuild .tools .utilities import nub
4344
4445
4546class EB_PyTorch (PythonPackage ):
@@ -49,9 +50,10 @@ class EB_PyTorch(PythonPackage):
4950 def extra_options ():
5051 extra_vars = PythonPackage .extra_options ()
5152 extra_vars .update ({
52- 'excluded_tests' : [{}, 'Mapping of architecture strings to list of tests to be excluded' , CUSTOM ],
53- 'custom_opts' : [[], 'List of options for the build/install command. Can be used to change the defaults ' +
54- 'set by the PyTorch EasyBlock, for example ["USE_MKLDNN=0"].' , CUSTOM ],
53+ 'custom_opts' : [[], "List of options for the build/install command. Can be used to change the defaults " +
54+ "set by the PyTorch EasyBlock, for example ['USE_MKLDNN=0']." , CUSTOM ],
55+ 'excluded_tests' : [{}, "Mapping of architecture strings to list of tests to be excluded" , CUSTOM ],
56+ 'max_failed_tests' : [10 , "Maximum number of failing tests" , CUSTOM ],
5557 })
5658 extra_vars ['download_dep_fail' ][0 ] = True
5759 extra_vars ['sanity_pip_check' ][0 ] = True
@@ -253,7 +255,30 @@ def test_step(self):
253255 'python' : self .python_cmd ,
254256 'excluded_tests' : ' ' .join (excluded_tests )
255257 })
256- super (EB_PyTorch , self ).test_step ()
258+
259+ (out , ec ) = super (EB_PyTorch , self ).test_step (return_output_ec = True )
260+ if ec :
261+ print_warning ("Test command had non-zero exit code (%s)!" % ec )
262+
263+ ran_tests_regex = re .compile (r"^Ran (?P<test_cnt>[0-9]+) tests in" , re .M )
264+ ran_tests_hits = ran_tests_regex .findall (out )
265+ test_cnt = 0
266+ for hit in ran_tests_hits :
267+ test_cnt += int (hit )
268+
269+ failed_test_regex = re .compile (r"^(?P<failed_test_name>.*) failed!\s*$" , re .M )
270+ failed_tests = nub (failed_test_regex .findall (out ))
271+ failed_test_cnt = len (failed_tests )
272+
273+ if failed_test_cnt :
274+ test_or_tests = 'tests' if failed_test_cnt > 1 else 'test'
275+ msg = "%d %s (out of %d tests) failed: %s"
276+ print_warning (msg , failed_test_cnt , test_or_tests , test_cnt , ', ' .join (failed_tests ))
277+
278+ max_failed_tests = self .cfg ['max_failed_tests' ]
279+ if failed_test_cnt > max_failed_tests :
280+ raise EasyBuildError ("Too many failed tests (%d), maximum allowed is %d" ,
281+ failed_test_cnt , max_failed_tests )
257282
258283 def test_cases_step (self ):
259284 # Make PyTorch tests not use the user home
0 commit comments