##// END OF EJS Templates
Shaperilio/qtgui fixes (#13957)...
Shaperilio/qtgui fixes (#13957) I started using the released version of my `PySide6`-enabling changes and noted some problems. In this PR, I fix those, and also overall improve the feedback to the user when a GUI event loop is hooked in: - Report which event loop is running when using `%gui <some GUI>`; e.g. `%gui qt` will show `Installed qt6 event loop hook.` - Report when the event loop is disabled; i.e. `%gui` will show `GUI event loop hook disabled.` if an event loop hook was installed, or `No event loop hook running.` if nothing was installed. - Requesting a second event loop will give the message `Shell is already running a gui event loop for <some GUI>. Call with no arguments to disable current loop.` - Requesting a different version of Qt, i.e. `%gui qt6` followed by `%gui` followed by `%gui qt5` will show `Cannot switch Qt versions for this session; will use qt6.` followed by `Installed qt6 event loop hook.` (Fixes / improves #13864)

File last commit:

r27386:82d1a374
r28163:88d1fedc merge
Show More
conftest.py
87 lines | 2.6 KiB | text/x-python | PythonLexer
import builtins
import inspect
import os
import pathlib
import shutil
import sys
import types
import pytest
# Must register before it gets imported
pytest.register_assert_rewrite("IPython.testing.tools")
from .testing import tools
def pytest_collection_modifyitems(items):
"""This function is automatically run by pytest passing all collected test
functions.
We use it to add asyncio marker to all async tests and assert we don't use
test functions that are async generators which wouldn't make sense.
"""
for item in items:
if inspect.iscoroutinefunction(item.obj):
item.add_marker("asyncio")
assert not inspect.isasyncgenfunction(item.obj)
def get_ipython():
from .terminal.interactiveshell import TerminalInteractiveShell
if TerminalInteractiveShell._instance:
return TerminalInteractiveShell.instance()
config = tools.default_config()
config.TerminalInteractiveShell.simple_prompt = True
# Create and initialize our test-friendly IPython instance.
shell = TerminalInteractiveShell.instance(config=config)
return shell
@pytest.fixture(scope='session', autouse=True)
def work_path():
path = pathlib.Path("./tmp-ipython-pytest-profiledir")
os.environ["IPYTHONDIR"] = str(path.absolute())
if path.exists():
raise ValueError('IPython dir temporary path already exists ! Did previous test run exit successfully ?')
path.mkdir()
yield
shutil.rmtree(str(path.resolve()))
def nopage(strng, start=0, screen_lines=0, pager_cmd=None):
if isinstance(strng, dict):
strng = strng.get("text/plain", "")
print(strng)
def xsys(self, cmd):
"""Replace the default system call with a capturing one for doctest.
"""
# We use getoutput, but we need to strip it because pexpect captures
# the trailing newline differently from commands.getoutput
print(self.getoutput(cmd, split=False, depth=1).rstrip(), end="", file=sys.stdout)
sys.stdout.flush()
# for things to work correctly we would need this as a session fixture;
# unfortunately this will fail on some test that get executed as _collection_
# time (before the fixture run), in particular parametrized test that contain
# yields. so for now execute at import time.
#@pytest.fixture(autouse=True, scope='session')
def inject():
builtins.get_ipython = get_ipython
builtins._ip = get_ipython()
builtins.ip = get_ipython()
builtins.ip.system = types.MethodType(xsys, ip)
builtins.ip.builtin_trap.activate()
from .core import page
page.pager_page = nopage
# yield
inject()