diff --git a/python/ql/test/query-tests/Statements/general/ShouldUseWithStatement.expected b/python/ql/test/query-tests/Statements/general/ShouldUseWithStatement.expected index 50ff6cc1f91..0ad3faa0032 100644 --- a/python/ql/test/query-tests/Statements/general/ShouldUseWithStatement.expected +++ b/python/ql/test/query-tests/Statements/general/ShouldUseWithStatement.expected @@ -1 +1,2 @@ | test.py:168:9:168:17 | Attribute() | Instance of context-manager class $@ is closed in a finally block. Consider using 'with' statement. | test.py:151:1:151:17 | Class CM | CM | +| test.py:182:13:182:26 | Attribute() | Instance of context-manager class $@ is closed in a finally block. Consider using 'with' statement. | test.py:151:1:151:17 | Class CM | CM | diff --git a/python/ql/test/query-tests/Statements/general/test.py b/python/ql/test/query-tests/Statements/general/test.py index a5848f7c718..77398958a5d 100644 --- a/python/ql/test/query-tests/Statements/general/test.py +++ b/python/ql/test/query-tests/Statements/general/test.py @@ -167,6 +167,20 @@ def no_with(): finally: f.close() +# Should use context manager, with the resource held in an instance attribute +# (caught via instance-attribute type tracking). +class HoldsCM(object): + + def __init__(self): + self.f = CM() + + def no_with_attribute(self): + try: + self.f.write("Hello ") + self.f.write(" World\n") + finally: + self.f.close() + #Assert without side-effect def assert_ok(seq): assert all(isinstance(element, (str, unicode)) for element in seq)