summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndrew Haigh <hello@nelf.in>2021-05-01 11:45:27 +1000
committerAndrew Haigh <hello@nelf.in>2021-05-24 19:32:06 +1000
commit38297611b6ebf32cd7722cce3074ce8fccccb490 (patch)
tree9a13224d4e5bb162b567077c16cde3cff1e7eb9e /tests
parent4a53ef4b151ace595608b5b5e6008b7b17914a80 (diff)
downloadastroid-git-38297611b6ebf32cd7722cce3074ce8fccccb490.tar.gz
Fix test definition of igetattr recursion and context_manager_inference
Ref #663. This test did not actually check for regression of the issue fixed in 55076ca0 (i.e. it also passed on c87bea17 before the fix was applied). Additionally, it over-specified the behaviour it was attempting to check: whether the value returned from the context manager was Uninferable was not directly relevant to the test, so when this value changed due to unrelated fixes in inference, this test failed.
Diffstat (limited to 'tests')
-rw-r--r--tests/unittest_inference.py25
1 files changed, 12 insertions, 13 deletions
diff --git a/tests/unittest_inference.py b/tests/unittest_inference.py
index 6b9f4c06..7006c8e3 100644
--- a/tests/unittest_inference.py
+++ b/tests/unittest_inference.py
@@ -5404,26 +5404,25 @@ def test_cannot_getattr_ann_assigns():
def test_prevent_recursion_error_in_igetattr_and_context_manager_inference():
code = """
class DummyContext(object):
- def method(self, msg): # pylint: disable=C0103
- pass
def __enter__(self):
- pass
+ return self
def __exit__(self, ex_type, ex_value, ex_tb):
return True
- class CallMeMaybe(object):
- def __call__(self):
- while False:
- with DummyContext() as con:
- f_method = con.method
- break
+ if False:
+ with DummyContext() as con:
+ pass
- with DummyContext() as con:
- con #@
- f_method = con.method
+ with DummyContext() as con:
+ con.__enter__ #@
"""
node = extract_node(code)
- assert next(node.infer()) is util.Uninferable
+ # According to the original issue raised that introduced this test
+ # (https://github.com/PyCQA/astroid/663, see 55076ca), this test was a
+ # non-regression check for StopIteration leaking out of inference and
+ # causing a RuntimeError. Hence, here just consume the inferred value
+ # without checking it and rely on pytest to fail on raise
+ next(node.infer())
def test_infer_context_manager_with_unknown_args():