<commit_before>import pytest

from pmxbot import logging


class TestLogging:
	@pytest.yield_fixture
	def logger(self, db_uri):
		logger = logging.Logger.from_URI(db_uri)
		try:
			yield logger
		finally:
			logger.clear()

	def test_get_random_logs(self, logger):
		logger.message('#inane', 'nik', 'message one')
		logger.message('#inane', 'nik', 'message two')
		messages = list(logger.get_random_logs(2))
		assert len(messages) == 2<commit_msg>In this case, addfinalizer is a more elegant approach.<commit_after>import pytest

from pmxbot import logging


class TestLogging:
	@pytest.fixture
	def logger(self, request, db_uri):
		logger = logging.Logger.from_URI(db_uri)
		request.addfinalizer(logger.clear)
		return logger

	def test_get_random_logs(self, logger):
		logger.message('#inane', 'nik', 'message one')
		logger.message('#inane', 'nik', 'message two')
		messages = list(logger.get_random_logs(2))
		assert len(messages) == 2
{'fraction_non_alphanumeric': 0.12566560170394037, 'fraction_numerical': 0.004259850905218318, 'mean_word_length': 5.438356164383562, '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': '4091547', 'n_tokens_mistral': 343, 'n_tokens_neox': 320, 'n_words': 76}