[TIP] Asserting all opened files have been closed

Jens Rantil jens.rantil at gmail.com
Sat Aug 11 03:12:33 PDT 2012


I have started using the Mock
library<http://www.voidspace.org.uk/python/mock/index.html>more and
more. It's great for some things that are hard to test otherwise.
At the same time, some of its concepts can be a little daunting to wrap my
head around.

That said, I have a test where I assert that all my opened files have been
properly closed throughout the lifetime of my application. It took me a
while to figure out how to write it. The current state of art can be found


I have to admit the code is quite cumbersome. So my question is, *can this
be done in a more compact/efficient manner?* I've been studying the "Mocking
open <http://www.voidspace.org.uk/python/mock/examples.html#mocking-open>"
example, but since I am not interested in asserting what was written, nor
read, it is not really helpful to me.

Oh, and as always, feel free to point me to any older threads discussing
this. I wish this mailing list was searchable...


Want to know how full my inbox is? Or how to get in touch with me faster?
Or tell me your e-mail is not that important? Then check this out:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20120811/d550744c/attachment.html>

More information about the testing-in-python mailing list