9
9
10
10
import astroid
11
11
from astroid import builder , nodes , objects , test_utils , util
12
+ from astroid .const import PY311_PLUS
12
13
from astroid .exceptions import InferenceError
13
14
14
15
try :
@@ -530,7 +531,8 @@ def test():
530
531
531
532
532
533
class ExceptionModelTest (unittest .TestCase ):
533
- def test_valueerror_py3 (self ) -> None :
534
+ @staticmethod
535
+ def test_valueerror_py3 () -> None :
534
536
ast_nodes = builder .extract_node (
535
537
"""
536
538
try:
@@ -544,12 +546,21 @@ def test_valueerror_py3(self) -> None:
544
546
)
545
547
assert isinstance (ast_nodes , list )
546
548
args = next (ast_nodes [0 ].infer ())
547
- self . assertIsInstance (args , astroid .Tuple )
549
+ assert isinstance (args , astroid .Tuple )
548
550
tb = next (ast_nodes [1 ].infer ())
549
- self .assertIsInstance (tb , astroid .Instance )
550
- self .assertEqual (tb .name , "traceback" )
551
-
552
- with self .assertRaises (InferenceError ):
551
+ # Python 3.11: If 'contextlib' is loaded, '__traceback__'
552
+ # could be set inside '__exit__' method in
553
+ # which case 'err.__traceback__' will be 'Uninferable'
554
+ try :
555
+ assert isinstance (tb , astroid .Instance )
556
+ assert tb .name == "traceback"
557
+ except AssertionError :
558
+ if PY311_PLUS :
559
+ assert tb == util .Uninferable
560
+ else :
561
+ raise
562
+
563
+ with pytest .raises (InferenceError ):
553
564
next (ast_nodes [2 ].infer ())
554
565
555
566
def test_syntax_error (self ) -> None :
0 commit comments