Tests / test_and_lint (push) Successful in 7s
Reviewed-on: #1 Co-authored-by: Mathias Scheider <mathias2784@web.de>
32 lines
1.2 KiB
Python
32 lines
1.2 KiB
Python
"""Make the test suite runnable on machines without Tk system libraries.
|
|
|
|
``utils.filedialogs`` imports tkinter at module level, and the CI runner
|
|
lacks the Tk shared libraries (``import tkinter`` fails on a missing
|
|
``libtk8.6.so``). Since pytest imports every test module at collection
|
|
time — including the deselected ``test_filedialogs_live.py`` — a minimal
|
|
stub is registered in ``sys.modules`` here, before any test module is
|
|
imported, whenever tkinter is not importable.
|
|
|
|
The hermetic tests in ``test_filedialogs.py`` mock every tkinter
|
|
touchpoint anyway, so the stub is never actually used.
|
|
"""
|
|
|
|
import sys
|
|
import types
|
|
|
|
try:
|
|
import tkinter # noqa: F401
|
|
except ImportError:
|
|
_tk_stub = types.ModuleType("tkinter")
|
|
_filedialog_stub = types.ModuleType("tkinter.filedialog")
|
|
|
|
def _tk_unavailable(*args, **kwargs):
|
|
raise AssertionError("real tkinter was called without a display")
|
|
|
|
_tk_stub.Tk = _tk_unavailable
|
|
_tk_stub.filedialog = _filedialog_stub
|
|
_filedialog_stub.askdirectory = _tk_unavailable
|
|
_filedialog_stub.askopenfilename = _tk_unavailable
|
|
sys.modules["tkinter"] = _tk_stub
|
|
sys.modules["tkinter.filedialog"] = _filedialog_stub
|