assertRaises must check for a specific exception
This product is not supported for your selected
Datadog site. (
).
이 페이지는 아직 영어로 제공되지 않습니다. 번역 작업 중입니다.
현재 번역 프로젝트에 대한 질문이나 피드백이 있으신 경우
언제든지 연락주시기 바랍니다.ID: python-best-practices/assertraises-specific-exception
Language: Python
Severity: Warning
Category: Error Prone
Description
When checking an exception, check for a specific exception. Checking for Exception may bypass the verification of the correct behavior of the program.
Using a generic exception is error-prone and give a false sense of correctness. Instead, use the correct exception to check against.
Non-Compliant Code Examples
self.assertRaises(Exception, foo) # check a specific Exception, not a generic one
Compliant Code Examples
self.assertRaises(ValueError, foo)
원활한 통합. Datadog Code Security를 경험해 보세요