<commit_before>import sys
from pathlib import Path

import matplotlib as mpl

mpl.use('agg')
from matplotlib import pyplot
from matplotlib.testing.compare import compare_images, make_test_filename
import pytest

import scanpy


scanpy.settings.verbosity = "hint"

# define this after importing scanpy but before running tests
IMPORTED = frozenset(sys.modules.keys())


@pytest.fixture(autouse=True)
def close_figures_on_teardown():
    yield
    pyplot.close("all")


@pytest.fixture
def imported_modules():<commit_msg>Maybe fix long test output (#1737)<commit_after>import sys
from pathlib import Path

import matplotlib as mpl

mpl.use('agg')
from matplotlib import pyplot
from matplotlib.testing.compare import compare_images, make_test_filename
import pytest

import scanpy


scanpy.settings.verbosity = "hint"

# define this after importing scanpy but before running tests
IMPORTED = frozenset(sys.modules.keys())


@pytest.fixture(autouse=True)
def close_figures_on_teardown():
    yield
    pyplot.close("all")


def clear_loggers():
    """Remove handlers from all loggers

    Fixes: https://github.com/theislab/scanpy/issues/1736

    Code from: https://github.com/pytest-dev/pytest/issues/5502#issuecomment-647157873
    """
    import logging

    loggers = [logging.getLogger()] + list(logging.Logger.manager.loggerDict.values())
    for logger in loggers:
        handlers = getattr(logger, 'handlers', [])
        for handler in handlers:
            logger.removeHandler(handler)


@pytest.fixture(scope="session", autouse=True)
def close_logs_on_teardown(request):
    request.addfinalizer(clear_loggers)


@pytest.fixture
def imported_modules():
{'fraction_non_alphanumeric': 0.0968129885748647, 'fraction_numerical': 0.012627781118460614, 'mean_word_length': 4.818181818181818, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '3794654', 'n_tokens_mistral': 547, 'n_tokens_neox': 527, 'n_words': 128}