[TIP] Better debugging of ResourceWarnings
marius at gedmin.as
Fri Jun 14 11:00:55 PDT 2013
On Thu, Jun 13, 2013 at 03:25:49PM -0400, Barry Warsaw wrote:
> I'm wondering if anybody has some advice for tracking down ResourceWarnings in
> a test suite of some code written for Python 3.3.
> I've got a few of these cropping up which are probably related to ssl sockets
> that aren't getting closed properly, but it's been difficult for me to track
> them down by code inspection alone. Even when I instrument my tox.ini file to
> run the tests with -Werror::ResourceWarning, I don't get much more output than
> test_load_index_with_device_keyring (resolver.tests.test_index.TestDownloadIndex) ... Exception ResourceWarning: ResourceWarning('unclosed <ssl.SSLSocket object, fd=5, family=2, type=1, proto=6>',) in <ssl.SSLSocket object, fd=5, family=2, type=1, proto=6> ignored
> I suspect that the warning isn't directly tied to this test though because it
> can occur in different places. It's probably due to something run by my
> ThreadPoolExecutor and could be caused by a mock.
> Just wondering if anybody has some general recommendations for getting better
> error reporting out of Python for these types of ResourceWarnings.
Sprinkling gc.collect() in all the suspicious tearDown() methods might
trigger these warnings sooner, and attribute them to the right test.
Running the tests in isolation might help too (I once had a monstrous
one-liner that piped zope.testrunner's bin/test --list-tests to a while
loop that ran each test in its own process via bin/test -t ^$test\$).
Smoking is one of the leading causes of statistics.
-- Fletcher Knebel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 190 bytes
Desc: Digital signature
More information about the testing-in-python