Like getattr but return default upon any Exception or any OutcomeException. Attribute access can potentially fail for 'evil' Python objects. See issue #214. It catches OutcomeException because of #2490 (issue #580), new outcomes are derived from BaseException instead of Exception (f
(object: Any, name: str, default: Any)
| 234 | |
| 235 | |
| 236 | def safe_getattr(object: Any, name: str, default: Any) -> Any: |
| 237 | """Like getattr but return default upon any Exception or any OutcomeException. |
| 238 | |
| 239 | Attribute access can potentially fail for 'evil' Python objects. |
| 240 | See issue #214. |
| 241 | It catches OutcomeException because of #2490 (issue #580), new outcomes |
| 242 | are derived from BaseException instead of Exception (for more details |
| 243 | check #2707). |
| 244 | """ |
| 245 | from _pytest.outcomes import TEST_OUTCOME |
| 246 | |
| 247 | try: |
| 248 | return getattr(object, name, default) |
| 249 | except TEST_OUTCOME: |
| 250 | return default |
| 251 | |
| 252 | |
| 253 | def safe_isclass(obj: object) -> bool: |
no outgoing calls