@@ -364,30 +364,27 @@ def _patch_unwrap_mock_aware():
364
364
contextmanager which replaces ``inspect.unwrap`` with a version
365
365
that's aware of mock objects and doesn't recurse on them
366
366
"""
367
- real_unwrap = getattr (inspect , "unwrap" , None )
368
- if real_unwrap is None :
369
- yield
370
- else :
371
-
372
- def _mock_aware_unwrap (obj , stop = None ):
373
- try :
374
- if stop is None or stop is _is_mocked :
375
- return real_unwrap (obj , stop = _is_mocked )
376
- return real_unwrap (obj , stop = lambda obj : _is_mocked (obj ) or stop (obj ))
377
- except Exception as e :
378
- warnings .warn (
379
- "Got %r when unwrapping %r. This is usually caused "
380
- "by a violation of Python's object protocol; see e.g. "
381
- "https://github.com/pytest-dev/pytest/issues/5080" % (e , obj ),
382
- PytestWarning ,
383
- )
384
- raise
367
+ real_unwrap = inspect .unwrap
385
368
386
- inspect . unwrap = _mock_aware_unwrap
369
+ def _mock_aware_unwrap ( obj , stop = None ):
387
370
try :
388
- yield
389
- finally :
390
- inspect .unwrap = real_unwrap
371
+ if stop is None or stop is _is_mocked :
372
+ return real_unwrap (obj , stop = _is_mocked )
373
+ return real_unwrap (obj , stop = lambda obj : _is_mocked (obj ) or stop (obj ))
374
+ except Exception as e :
375
+ warnings .warn (
376
+ "Got %r when unwrapping %r. This is usually caused "
377
+ "by a violation of Python's object protocol; see e.g. "
378
+ "https://github.com/pytest-dev/pytest/issues/5080" % (e , obj ),
379
+ PytestWarning ,
380
+ )
381
+ raise
382
+
383
+ inspect .unwrap = _mock_aware_unwrap
384
+ try :
385
+ yield
386
+ finally :
387
+ inspect .unwrap = real_unwrap
391
388
392
389
393
390
class DoctestModule (pytest .Module ):
0 commit comments