[TIP] parametrize a pytest finalizer

Pella,Chris Chris.Pella at safenet-inc.com
Wed Apr 9 14:15:38 PDT 2014


It doesn't seem possible to pass arguments to a pytest finalizer. I can work around it this way, but it seems exceedingly ugly:

@pytest.fixture(scope = "class")
def test_fixture(request):

    global cleanup_parameter
    cleanup_parameter = "Cleaning up"

    def cleanup():
        global cleanup_parameter
        print cleanup_parameter

    try:
        raise
    except Exception:
        cleanup_parameter = "Problem in fixture!"
        cleanup()

    request.addfinalizer(cleanup)


Is there a better way?

The information contained in this electronic mail transmission 
may be privileged and confidential, and therefore, protected 
from disclosure. If you have received this communication in 
error, please notify us immediately by replying to this 
message and deleting it from your computer without copying 
or disclosing it.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20140409/dda44d08/attachment.htm>


More information about the testing-in-python mailing list