Summary
Like #1945, rule open-file-with-context-handler (SIM115) should exempt context managers passed to the TestCase.enterContext() and enterClassContext() methods. These methods methods act like with, so there’s no concern around the file not being closed.
Currently, an error is triggered for this code:
class ExampleTests(TestCase):
def setUp(self):
self.example_csv = self.enterContext(open("example.csv"))
Output:
example.py:6:46: SIM115 Use a context manager for opening files
|
4 | class ExampleTests(TestCase):
5 | def setUp(self):
6 | self.example_csv = self.enterContext(open("example.csv"))
| ^^^^ SIM115
|
Found 1 error.
Version
0.9.7