<commit_before>import pytest
import api.common

from functools import wraps

def clear_collections(*collections):
    """
    Clears collections listed after function has completed.
    """
    def clear(f):
        @wraps(f)
        def wrapper(*args, **kwargs):
            result = f(*args, **kwargs)

            db = api.common.get_conn()
            for collection in collections:
                db[collection].remove()
                assert len(list(db[collection].find())) == 0, "Unable to clear collection: " + collection

            return result
        return wrapper
    return clear<commit_msg>clear_collections will now work even if an exception is thrown.<commit_after>import pytest
import api.common

from functools import wraps

def clear_collections(*collections):
    """
    Clears collections listed after function has completed.
    """
    def clear(f):
        @wraps(f)
        def wrapper(*args, **kwargs):
            try:
                result = f(*args, **kwargs)
            except Exception:
                raise
            finally:
                db = api.common.get_conn()
                for collection in collections:
                    db[collection].remove()
                    assert len(list(db[collection].find())) == 0, "Unable to clear collection: " + collection

            return result
        return wrapper
    return clear
{'fraction_non_alphanumeric': 0.09268645908761766, 'fraction_numerical': 0.001448225923244026, 'mean_word_length': 1.997830802603037, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5085581', 'n_tokens_mistral': 348, 'n_tokens_neox': 337, 'n_words': 107}