From 427d422e150dfdb442bd0d34b2421b3db3ab3a14 Mon Sep 17 00:00:00 2001 From: Andrew Haigh Date: Sat, 1 May 2021 11:45:27 +1000 Subject: [PATCH] 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. --- tests/unittest_inference.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/tests/unittest_inference.py b/tests/unittest_inference.py index ce15e1efd1..852880ff3d 100644 --- a/tests/unittest_inference.py +++ b/tests/unittest_inference.py @@ -5312,26 +5312,20 @@ class Cls: 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 + next(node.infer()) # should not raise StopIteration/RuntimeError def test_infer_context_manager_with_unknown_args():