headless-safe filedialog tests with optional live dialog tests and ruff fixes
Tests / test_and_lint (push) Failing after 7s
Tests / test_and_lint (push) Failing after 7s
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
"""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
|
||||
Reference in New Issue
Block a user