Skip to content

Commit 8d14d57

Browse files
committed
Refactor test_matplotlib_inline_on_import to see if can fix test for macos.
1 parent 8ae4892 commit 8d14d57

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
@pytest.hookimpl
3232
def pytest_configure(config):
3333
os.environ["PYTEST_TIMEOUT"] = str(1e6) if async_kernel.utils.LAUNCHED_BY_DEBUGPY else str(utils.TIMEOUT)
34+
os.environ["MPLBACKEND"] = utils.MATPLOTLIB_INLINE_BACKEND
3435

3536

3637
@pytest.fixture(scope="module")

tests/test_kernel.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -408,13 +408,14 @@ class user_mod:
408408
kernel.user_ns = {}
409409

410410

411-
async def test_matplotlib_inline_on_import(client):
412-
pytest.importorskip("matplotlib", reason="this test requires matplotlib")
411+
async def test_matplotlib_inline_on_import(subprocess_kernels_client):
412+
import matplotlib as mpl # noqa: PLC0415
413+
414+
assert mpl.get_backend() == utils.MATPLOTLIB_INLINE_BACKEND
413415
code = "\n".join(["import matplotlib, matplotlib.pyplot as plt", "backend = matplotlib.get_backend()"])
414-
_, reply = await utils.execute(client, code, user_expressions={"backend": "backend"})
415-
backend_bundle = reply["user_expressions"]["backend"]
416-
assert "backend_inline" in backend_bundle["data"]["text/plain"]
417-
await utils.clear_iopub(client)
416+
_, reply = await utils.execute(subprocess_kernels_client, code, user_expressions={"backend": "backend"})
417+
backend = eval(reply["user_expressions"]["backend"]["data"]["text/plain"])
418+
assert backend == utils.MATPLOTLIB_INLINE_BACKEND
418419

419420

420421
@pytest.mark.parametrize("code", ["%connect_info", "%matplotlib --list", "%callers"])

tests/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222

2323
TIMEOUT = 10 if not async_kernel.utils.LAUNCHED_BY_DEBUGPY else 1e6
24+
MATPLOTLIB_INLINE_BACKEND = "module://matplotlib_inline.backend_inline"
2425

2526

2627
class ExecuteContentType(TypedDict):

0 commit comments

Comments
 (0)