[py-dev] Exceptions in setup/teardown hooks

Matthew Edwards monopocalypse+py-dev at gmail.com
Sun Aug 10 22:17:59 CEST 2008


Hi,

I've got some tests for a module which manages log files. The setup_class
and teardown_class functions create and delete a directory for them, and the
teardown_method function deletes the individual files based on a list. When
a test fails, it can leave files which aren't on the list, so don't get
deleted in teardown_method, which makes teardown_class choke on os.rmdir
(because the directory is not empty). While I do need to know if there are
files left over, the problem is that when an exception occurs in a hook, it
shows a traceback for that only, and not the actual test failure, so I can't
tell what failed.

Am I just doing this wrong, or is this a bit of a bug? I would prefer an
exception in [setup|teardown]_method to fail that method, and an exception
in [setup|teardown]_class to fail all the tests in that class, and if an
exception is raised in a test and the following hook, tracebacks for both
should be displayed.

As an aside, stdout capture doesn't work particularly well from the hooks
either.

Matthew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20080811/2cb55537/attachment.html>


More information about the Pytest-dev mailing list