File: conftest.py

package info (click to toggle)
fonttools 4.61.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 27,584 kB
  • sloc: python: 145,091; xml: 103; makefile: 24
file content (28 lines) | stat: -rw-r--r-- 1,024 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import fontTools
import pytest


@pytest.fixture(autouse=True, scope="session")
def disableConfigLogger():
    """Session-scoped fixture to make fontTools.configLogger function no-op.

    Logging in python maintains a global state. When in the tests we call a main()
    function from modules subset or ttx, a call to configLogger is made that modifies
    this global state (to configures a handler for the fontTools logger).
    To prevent that, we monkey-patch the `configLogger` attribute of the `fontTools`
    module (the one used in the scripts main() functions) so that it does nothing,
    to avoid any side effects.

    NOTE: `fontTools.configLogger` is only an alias for the configLogger function in
    `fontTools.misc.loggingTools` module; the original function is not modified.
    """

    def noop(*args, **kwargs):
        return

    originalConfigLogger = fontTools.configLogger
    fontTools.configLogger = noop
    try:
        yield
    finally:
        fontTools.configLogger = originalConfigLogger