You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
make embed kernel and kernelapp tests independent of test order - #1608
A few tests depend on what earlier tests left behind, so they pass in the default order but fail
when the order changes (pytest-randomly, pytest-xdist, or running a single file).
test_embed_kernel_func and test_start_app need a current asyncio event loop and don't create
one. Run on their own on Python 3.12, they fail with "DeprecationWarning: There is no current
event loop" (an error with this repo's filterwarnings). They only pass when an earlier test
happened to leave a loop set.
When test_embed_kernel_func fails, it never clears the IPKernelApp and ZMQInteractiveShell
singletons, so later tests that create an app or an in-process shell fail with MultipleInstanceError. That's what happened in Six tests failing with ipykernel 6.29.5 and Python 3.13 on Debian #1302: a Python 3.13 failure in test_embed_kernel_func also failed test_install_kernelspec and test_zmq_interactive_shell. start testing on 3.13 #1277 fixed that trigger, but the leftover singletons are still there.
test_install_kernelspec leaves InstallIPythonKernelSpecApp as a singleton, which breaks test_embed_kernel_func if it runs later.
a new_event_loop fixture in conftest.py that gives a sync test its own event loop and closes it
afterwards, used by test_embed_kernel_func and test_start_app
test_embed_kernel_func joins its stop thread and clears IPKernelApp and ZMQInteractiveShell
in a finally block
Related: #1583 fixes the missing event loop in IPKernelApp.start() for #1582. That covers test_embed_kernel_func's event loop problem, but not test_start_app (it fails while creating the
kernel, before start()) or the singleton leaks. Happy to drop the fixture from test_embed_kernel_func once #1583 is in.
Also fixes test_sys_path_profile_dir, which used the default IPython profile and failed when it ran before any test that creates it.
I added a second commit for another test with the same kind of problem: test_sys_path_profile_dir used the default IPython profile, which only exists if an earlier test already started IPython. When it runs first it fails with OSError: Couldn't find profile 'default'. It now uses a temporary profile dir instead. To reproduce on main:
To check the whole pr, I ran the full suite 60 times in shuffled order (pytest-randomly, with some runs CPU limited) on main at 7940a09 and on this branch:
The 4 left on this branch were test_sys_path_profile_dir (1/60, fixed by the new commit) and 3 tests that failed once or twice in 130+ runs with no pattern, which look unrelated.
One more thing the thread.join() fixes: when embed_kernel failed right away, the trigger_stop thread outlived the test and raised about a second later, during whichever test was running then. pytest reported that as PytestUnhandledThreadExceptionWarning, and since warnings are errors in this repo, a random later test failed. I saw it hit test_comm_in_manager and test_ipython_start_kernel_no_userns. Neither failed on this branch.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A few tests depend on what earlier tests left behind, so they pass in the default order but fail
when the order changes (pytest-randomly, pytest-xdist, or running a single file).
test_embed_kernel_funcandtest_start_appneed a current asyncio event loop and don't createone. Run on their own on Python 3.12, they fail with "DeprecationWarning: There is no current
event loop" (an error with this repo's filterwarnings). They only pass when an earlier test
happened to leave a loop set.
When
test_embed_kernel_funcfails, it never clears theIPKernelAppandZMQInteractiveShellsingletons, so later tests that create an app or an in-process shell fail with
MultipleInstanceError. That's what happened in Six tests failing with ipykernel 6.29.5 and Python 3.13 on Debian #1302: a Python 3.13 failure intest_embed_kernel_funcalso failedtest_install_kernelspecandtest_zmq_interactive_shell.start testing on 3.13 #1277 fixed that trigger, but the leftover singletons are still there.
test_install_kernelspecleavesInstallIPythonKernelSpecAppas a singleton, which breakstest_embed_kernel_funcif it runs later.To reproduce on main:
All three fail on main and pass with this change.
Changes (tests only):
new_event_loopfixture in conftest.py that gives a sync test its own event loop and closes itafterwards, used by
test_embed_kernel_funcandtest_start_apptest_embed_kernel_funcjoins its stop thread and clearsIPKernelAppandZMQInteractiveShellin a finally block
test_install_kernelspecclearsInstallIPythonKernelSpecAppafterwardsRelated: #1583 fixes the missing event loop in
IPKernelApp.start()for #1582. That coverstest_embed_kernel_func's event loop problem, but nottest_start_app(it fails while creating thekernel, before
start()) or the singleton leaks. Happy to drop the fixture fromtest_embed_kernel_funconce #1583 is in.Also fixes test_sys_path_profile_dir, which used the default IPython profile and failed when it ran before any test that creates it.