是的,可以这样做。但是,被测函数必须存在于其他模块中:
# test1.pytry: import test2except IndentationError as ex: print ex# test2.pydef f(): pass pass # error
运行时,这将正确捕获异常。一次对整个模块进行检查是毫无意义的;我不确定是否有办法使它更细。

是的,可以这样做。但是,被测函数必须存在于其他模块中:
# test1.pytry: import test2except IndentationError as ex: print ex# test2.pydef f(): pass pass # error
运行时,这将正确捕获异常。一次对整个模块进行检查是毫无意义的;我不确定是否有办法使它更细。