diff options
| author | Marc Mueller <30130371+cdce8p@users.noreply.github.com> | 2022-05-13 23:37:55 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-13 23:37:55 +0200 |
| commit | fb31eede489b45498e65b1921b537f7bd2dd8c9b (patch) | |
| tree | d0c34af9435fb55726f721f7254f4f2459e0546d /tests | |
| parent | fd102d45a3552c00d951a07b02c49d278a7a69a2 (diff) | |
| download | astroid-git-fb31eede489b45498e65b1921b537f7bd2dd8c9b.tar.gz | |
Fix 3.11 test (#1558)
Issue with reassigned __traceback__ attribute.
In some cases it can be uninferable now.
Ref: #1551
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/unittest_object_model.py | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/tests/unittest_object_model.py b/tests/unittest_object_model.py index a9f9f1f1..3cf2e4ae 100644 --- a/tests/unittest_object_model.py +++ b/tests/unittest_object_model.py @@ -9,6 +9,7 @@ import pytest import astroid from astroid import builder, nodes, objects, test_utils, util +from astroid.const import PY311_PLUS from astroid.exceptions import InferenceError try: @@ -530,7 +531,8 @@ class GeneratorModelTest(unittest.TestCase): class ExceptionModelTest(unittest.TestCase): - def test_valueerror_py3(self) -> None: + @staticmethod + def test_valueerror_py3() -> None: ast_nodes = builder.extract_node( """ try: @@ -544,12 +546,21 @@ class ExceptionModelTest(unittest.TestCase): ) assert isinstance(ast_nodes, list) args = next(ast_nodes[0].infer()) - self.assertIsInstance(args, astroid.Tuple) + assert isinstance(args, astroid.Tuple) tb = next(ast_nodes[1].infer()) - self.assertIsInstance(tb, astroid.Instance) - self.assertEqual(tb.name, "traceback") - - with self.assertRaises(InferenceError): + # Python 3.11: If 'contextlib' is loaded, '__traceback__' + # could be set inside '__exit__' method in + # which case 'err.__traceback__' will be 'Uninferable' + try: + assert isinstance(tb, astroid.Instance) + assert tb.name == "traceback" + except AssertionError: + if PY311_PLUS: + assert tb == util.Uninferable + else: + raise + + with pytest.raises(InferenceError): next(ast_nodes[2].infer()) def test_syntax_error(self) -> None: |
