xref: /aosp_15_r20/external/fonttools/Tests/conftest.py (revision e1fe3e4ad2793916b15cccdc4a7da52a7e1dd0e9)
1*e1fe3e4aSElliott Hughesimport fontTools
2*e1fe3e4aSElliott Hughesimport pytest
3*e1fe3e4aSElliott Hughes
4*e1fe3e4aSElliott Hughes
5*e1fe3e4aSElliott Hughes@pytest.fixture(autouse=True, scope="session")
6*e1fe3e4aSElliott Hughesdef disableConfigLogger():
7*e1fe3e4aSElliott Hughes    """Session-scoped fixture to make fontTools.configLogger function no-op.
8*e1fe3e4aSElliott Hughes
9*e1fe3e4aSElliott Hughes    Logging in python maintains a global state. When in the tests we call a main()
10*e1fe3e4aSElliott Hughes    function from modules subset or ttx, a call to configLogger is made that modifies
11*e1fe3e4aSElliott Hughes    this global state (to configures a handler for the fontTools logger).
12*e1fe3e4aSElliott Hughes    To prevent that, we monkey-patch the `configLogger` attribute of the `fontTools`
13*e1fe3e4aSElliott Hughes    module (the one used in the scripts main() functions) so that it does nothing,
14*e1fe3e4aSElliott Hughes    to avoid any side effects.
15*e1fe3e4aSElliott Hughes
16*e1fe3e4aSElliott Hughes    NOTE: `fontTools.configLogger` is only an alias for the configLogger function in
17*e1fe3e4aSElliott Hughes    `fontTools.misc.loggingTools` module; the original function is not modified.
18*e1fe3e4aSElliott Hughes    """
19*e1fe3e4aSElliott Hughes
20*e1fe3e4aSElliott Hughes    def noop(*args, **kwargs):
21*e1fe3e4aSElliott Hughes        return
22*e1fe3e4aSElliott Hughes
23*e1fe3e4aSElliott Hughes    originalConfigLogger = fontTools.configLogger
24*e1fe3e4aSElliott Hughes    fontTools.configLogger = noop
25*e1fe3e4aSElliott Hughes    try:
26*e1fe3e4aSElliott Hughes        yield
27*e1fe3e4aSElliott Hughes    finally:
28*e1fe3e4aSElliott Hughes        fontTools.configLogger = originalConfigLogger
29