-
Type: Bug
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: None
-
None
-
Python Drivers
-
Not Needed
-
MongoClient with connect=False still generates a resource warning:
def test_client_options(self): c = MongoClient(connect=False) self.assertIsInstance(c.options, ClientOptions) self.assertIsInstance(c.options.pool_options, PoolOptions) self.assertEqual(c.options.server_selection_timeout, 30) self.assertEqual(c.options.pool_options.max_idle_time_seconds, None) self.assertIsInstance(c.options.retry_writes, bool) self.assertIsInstance(c.options.retry_reads, bool)
Generates this warning:
test_client_options (__main__.ClientUnitTest.test_client_options) ... /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/case.py:589: ResourceWarning: Unclosed MongoClient opened at: File "/Users/shane/git/mongo-python-driver/test/test_client.py", line 2459, in <module> unittest.main() File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/main.py", line 105, in __init__ self.runTests() File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/main.py", line 281, in runTests self.result = testRunner.run(self.test) File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/runner.py", line 240, in run test(result) File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/suite.py", line 84, in __call__ return self.run(*args, **kwds) File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/suite.py", line 122, in run test(result) File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/suite.py", line 84, in __call__ return self.run(*args, **kwds) File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/suite.py", line 122, in run test(result) File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/case.py", line 690, in __call__ return self.run(*args, **kwds) File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/case.py", line 634, in run self._callTestMethod(testMethod) File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/case.py", line 589, in _callTestMethod if method() is not None: File "/Users/shane/git/mongo-python-driver/test/test_client.py", line 579, in test_client_options c = MongoClient(connect=False) Call MongoClient.close() to safely shut down your client and free up resources. if method() is not None: ResourceWarning: Enable tracemalloc to get the object allocation traceback
- is caused by
-
PYTHON-3193 Add ResourceWarning for unclosed MongoClients in __del__
- Closed