我定义了以下异常:
for const in btnSound.constraints {
if const.identifier == "constBtnSound" {
...
}
}
现在,我在通过class ArgumentsException(Exception):
"""Exception that is raised when incorrect arguments are used."""
pass
程序包运行程序的地方运行测试。并且当引发此预期异常时,sh
会捕获该异常本身,然后重新引发自己的异常。我有办法检查我的原始异常是否以某种方式提出了吗?
例如,当我运行此代码时(预计此代码会引发该异常):
sh
我得到了这个异常:
sh.python3(
self.main_py_path,
self.live_cfg_path,
self.workflow_cfg_path)
好吧,我可以做类似的事情:
Traceback (most recent call last):
File "/home/oerp/src/devops-tools/tests/test_main.py", line 153, in test_full_workflow_1
self.workflow_cfg_path)
File "/usr/local/lib/python3.5/dist-packages/sh.py", line 1427, in __call__
return RunningCommand(cmd, call_args, stdin, stdout, stderr)
File "/usr/local/lib/python3.5/dist-packages/sh.py", line 774, in __init__
self.wait()
File "/usr/local/lib/python3.5/dist-packages/sh.py", line 792, in wait
self.handle_command_exit_code(exit_code)
File "/usr/local/lib/python3.5/dist-packages/sh.py", line 815, in handle_command_exit_code
raise exc
sh.ErrorReturnCode_1:
RAN: /usr/bin/python3 /home/oerp/src/devops-tools/main.py /home/oerp/src/devops-tools/tests/configs/__live__.py /home/oerp/src/devops-tools/tests/configs/__workflow__.py
STDOUT:
STDERR:
Traceback (most recent call last):
File "/home/oerp/src/devops-tools/main.py", line 204, in <module>
state = _get_state(args.state, ignore_state=args.ignore_state)
File "/home/oerp/src/devops-tools/main.py", line 68, in _get_state
"__state__.py file must be provided if --ignore-state flag "
exceptions.ArgumentsException: __state__.py file must be provided if --ignore-state flag is not used.
但是也许有更优雅的方法来检查我的异常?