import tempfile
import shutil


def storage(request):
    """
    Returns a string that describes the storage type, and a list containing
    arguments for the storage backend.
    Perform setup & teardown for storage.
    """
    # py.test-provided fixture "tmpdir" does not guarantee an empty temp
    # directory, which get re-used when test is run again - rolling our own...
    args = []
    if request.param == 'diskstorage':
        tmpdir = tempfile.mkdtemp('rebus-test-%s' % request.param)
        args = ['diskstorage', '--path', tmpdir]

        def fin():
            shutil.rmtree(tmpdir)
        request.addfinalizer(fin)

    return (request.param, args)