MCPcopy Index your code
hub / github.com/python/cpython / raises

Method raises

Lib/importlib/metadata/_context.py:72–97  ·  view source on GitHub ↗

Wrap func and replace the result with the truth value of the trap (True if an exception occurred). First, give the decorator an alias to support Python 3.8 Syntax. >>> raises = ExceptionTrap(ValueError).raises Now decorate a function that always fa

(self, func, *, _test=bool)

Source from the content-addressed store, hash-verified

70 return bool(self.type)
71
72 def raises(self, func, *, _test=bool):
73 """
74 Wrap func and replace the result with the truth
75 value of the trap (True if an exception occurred).
76
77 First, give the decorator an alias to support Python 3.8
78 Syntax.
79
80 >>> raises = ExceptionTrap(ValueError).raises
81
82 Now decorate a function that always fails.
83
84 >>> @raises
85 ... def fail():
86 ... raise ValueError('failed')
87 >>> fail()
88 True
89 """
90
91 @functools.wraps(func)
92 def wrapper(*args, **kwargs):
93 with ExceptionTrap(self.exceptions) as trap:
94 func(*args, **kwargs)
95 return _test(trap)
96
97 return wrapper
98
99 def passes(self, func):
100 """

Callers 1

passesMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected