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