Is there a way to make Python 3 unittest crash, and not just display a warning on stderr if it calls any resource?
I tried the following:
import warnings warnings.simplefilter(action='error', category=ResourceWarning)
The result of this result is unittest:
my_test (__main__.MyTest) ... Exception ignored in: <socket.socket fd=9, family=AddressFamily.AF_INET, type=SocketType.SOCK_STREAM, proto=0, laddr=('127.0.0.1', 54065), raddr=('127.0.0.1', 27017)> ResourceWarning: unclosed <socket.socket fd=9, family=AddressFamily.AF_INET, type=SocketType.SOCK_STREAM, proto=0, laddr=('127.0.0.1', 54065), raddr=('127.0.0.1', 27017)> ok ---------------------------------------------------------------------- Ran 1 test in 0.110s
Note the message "Exception ignored." I would prefer that the test fail, rather than requiring me to read its output in search of ResourceWarnings.
A. Jesse Jiryu Davis
source share