Skip to content

Compatibility with Python 3.13 #316

Open
@frenzymadness

Description

@frenzymadness

Hello.

The tests are failing when run with Python 3.13.0 beta 2:

___________ test_output[{notebook_name}-new.ipynb-True-input_names2] ___________
input_names = ('Other Comms', 'HelloWorld.ipynb'), relative = True
output_base = '{notebook_name}-new.ipynb'
jupyterapp = <MagicMock name='initialize' id='139933392544368'>
client = <MagicMock name='NotebookClient' spec='NotebookClient' id='139933392544704'>
reader = <function read at 0x7f44c7fcec00>
writer = <function write at 0x7f44c7fcf2e0>
path_open = <MagicMock name='open' id='139933390354960'>
    @pytest.mark.parametrize(
        "input_names", [("Other Comms",), ("Other Comms.ipynb",), ("Other Comms", "HelloWorld.ipynb")]
    )
    @pytest.mark.parametrize("relative", [False, True])
    @pytest.mark.parametrize("output_base", ["thing", "thing.ipynb", "{notebook_name}-new.ipynb"])
    def test_output(input_names, relative, output_base, jupyterapp, client, reader, writer, path_open):
        paths = [current_dir / "files" / name for name in input_names]
        if relative:
            paths = [p.relative_to(Path.cwd()) for p in paths]
    
        c = NbClientApp(
            notebooks=[str(p) for p in paths], kernel_name="python3", output_base=output_base
        )
    
        if len(paths) != 1 and "{notebook_name}" not in output_base:
            with pytest.raises(ValueError) as e:
                c.initialize()
            assert "If passing multiple" in str(e.value)
            return
    
        c.initialize()
    
        # add suffix if needed
        paths = [p.with_suffix(".ipynb") for p in paths]
    
>       assert path_open.mock_calls[::3] == [call(p) for p in paths]
E       AssertionError: assert [call(PosixPath('tests/files/Other Comms.ipynb')), call().close(), call().__exit__(None, None, None)] == [call(PosixPath('tests/files/Other Comms.ipynb')), call(PosixPath('tests/files/HelloWorld.ipynb'))]
E         At index 1 diff: call().close() != call(PosixPath('tests/files/HelloWorld.ipynb'))
E         Left contains one more item: call().__exit__(None, None, None)
E         Full diff:
E           [
E            call(PosixPath('tests/files/Other Comms.ipynb')),
E         -  call(PosixPath('tests/files/HelloWorld.ipynb')),
E         +  call().close(),
E         +  call().__exit__(None, None, None),
E           ]
c          = <nbclient.cli.NbClientApp object at 0x7f44c80279d0>
client     = <MagicMock name='NotebookClient' spec='NotebookClient' id='139933392544704'>
input_names = ('Other Comms', 'HelloWorld.ipynb')
jupyterapp = <MagicMock name='initialize' id='139933392544368'>
output_base = '{notebook_name}-new.ipynb'
path_open  = <MagicMock name='open' id='139933390354960'>
paths      = [PosixPath('tests/files/Other Comms.ipynb'),
 PosixPath('tests/files/HelloWorld.ipynb')]
reader     = <function read at 0x7f44c7fcec00>
relative   = True
writer     = <function write at 0x7f44c7fcf2e0>
tests/test_cli.py:117: AssertionError
----------------------------- Captured stderr call -----------------------------
[NbClientApp] Executing tests/files/Other Comms
[NbClientApp] Save executed results to tests/files/Other Comms-new.ipynb
[NbClientApp] Executing tests/files/HelloWorld.ipynb
[NbClientApp] Save executed results to tests/files/HelloWorld-new.ipynb
=============================== warnings summary ===============================
../../../../../usr/lib/python3.13/site-packages/jupyter_client/connect.py:22
  /usr/lib/python3.13/site-packages/jupyter_client/connect.py:22: DeprecationWarning: Jupyter is migrating its paths to use standard platformdirs
  given by the platformdirs library.  To remove this warning and
  see the appropriate new directories, set the environment variable
100  183k  100  183k    RM_DIRS=1` and then run `jupyter --paths`.
  The use of platformdirs will be the default in `jupyter_core` v6
    from jupyter_core.paths import jupyter_data_dir, jupyter_runtime_dir, secure_write
tests/test_client.py::test_start_new_kernel_history_file_setting
  /usr/lib64/python3.13/subprocess.py:1137: ResourceWarning: subprocess 980 is still running
    _warn("subprocess %s is still running" % self.pid,
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.
tests/test_client.py::test_start_new_kernel_client_cleans_up_kernel_on_failure
  /usr/lib64/python3.13/subprocess.py:1137: ResourceWarning: subprocess 963 is still running
    _warn("subprocess %s is still running" % self.pid,
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.
tests/test_client.py::test_start_new_kernel_client_cleans_up_kernel_on_failure
  /usr/lib64/python3.13/subprocess.py:1137: ResourceWarning: subprocess 983 is still running
    _warn("subprocess %s is still running" % self.pid,
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.
tests/test_client.py::TestExecute::test_error_async_execution_hook
  /usr/lib64/python3.13/unittest/mock.py:2218: ResourceWarning: Unclosed socket <zmq.asyncio.Socket(zmq.DEALER) at 0x7f44c7af34d0>
    def __init__(self, name, parent):
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.
tests/test_client.py::TestExecute::test_error_async_execution_hook
  /usr/lib64/python3.13/unittest/mock.py:2218: ResourceWarning: Unclosed socket <zmq.asyncio.Socket(zmq.DEALER) at 0x7f44c7b49e10>
    def __init__(self, name, parent):
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.
tests/test_client.py::TestExecute::test_timeout_func
  /usr/lib/python3.13/site-packages/traitlets/config/configurable.py:180: ResourceWarning: Unclosed socket <zmq.asyncio.Socket(zmq.DEALER) at 0x7f44c7a1d7f0>
    for name, config_value in my_config.items():
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.
tests/test_client.py::TestExecute::test_timeout_func
  /usr/lib/python3.13/site-packages/traitlets/config/configurable.py:180: ResourceWarning: Unclosed socket <zmq.asyncio.Socket(zmq.DEALER) at 0x7f44c7a1dda0>
    for name, config_value in my_config.items():
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.
tests/test_client.py: 38 warnings
  /builddir/build/BUILD/python-nbclient-0.10.0-build/nbclient-0.10.0/nbclient/client.py:57: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
    return datetime.datetime.utcnow().isoformat() + "Z"
tests/test_client.py: 15 warnings
  /usr/lib64/python3.13/asyncio/base_events.py:760: ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=False>
    _warn(f"unclosed event loop {self!r}", ResourceWarning, source=self)
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
===Flaky Test Report===
test_parallel_notebooks passed 1 out of the required 1 times. Success!
test_many_parallel_notebooks passed 1 out of the required 1 times. Success!
test_async_parallel_notebooks passed 1 out of the required 1 times. Success!
test_many_async_parallel_notebooks passed 1 out of the required 1 times. Success!
test_kernel_death_after_timeout passed 1 out of the required 1 times. Success!
===End Flaky Test Report===
============================= slowest 10 durations =============================
11.32s call     tests/test_client.py::TestExecute::test_timeout_func
5.65s call     tests/test_client.py::test_many_parallel_notebooks
5.27s call     tests/test_client.py::TestExecute::test_sync_kernel_manager
4.28s call     tests/test_client.py::test_run_all_notebooks[Interrupt.ipynb-opts6]
4.05s call     tests/test_client.py::TestExecute::test_kernel_death_after_timeout
4.02s call     tests/test_client.py::TestExecute::test_populate_language_info
4.02s call     tests/test_client.py::test_synchronous_setup_kernel
2.15s call     tests/test_client.py::TestExecute::test_timeout
2.09s call     tests/test_client.py::test_many_async_parallel_notebooks
2.01s call     tests/test_client.py::test_execution_timing
=========================== short test summary info ============================
FAILED tests/test_cli.py::test_mult[False-False-input_names0] - AssertionError: assert [call(PosixPath('/builddir/build/BUILD/python-nbclie...
FAILED tests/test_cli.py::test_mult[False-False-input_names1] - AssertionError: assert [call(PosixPath('/builddir/build/BUILD/python-nbclie...
FAILED tests/test_cli.py::test_mult[False-False-input_names2] - AssertionError: assert [call(PosixPath('/builddir/build/BUILD/python-nbclie...
FAILED tests/test_cli.py::test_mult[False-True-input_names0] - AssertionError: assert [call(PosixPath('tests/files/Other Comms.ipynb')), c...
FAILED tests/test_cli.py::test_mult[False-True-input_names1] - AssertionError: assert [call(PosixPath('tests/files/Other Comms.ipynb')), c...
FAILED tests/test_cli.py::test_mult[False-True-input_names2] - AssertionError: assert [call(PosixPath('tests/files/Other Comms.ipynb')), c...
FAILED tests/test_cli.py::test_mult[True-False-input_names0] - AssertionError: assert [call(PosixPath('/builddir/build/BUILD/python-nbclie...
FAILED tests/test_cli.py::test_mult[True-False-input_names1] - AssertionError: assert [call(PosixPath('/builddir/build/BUILD/python-nbclie...
FAILED tests/test_cli.py::test_mult[True-False-input_names2] - AssertionError: assert [call(PosixPath('/builddir/build/BUILD/python-nbclie...
FAILED tests/test_cli.py::test_mult[True-True-input_names0] - AssertionError: assert [call(PosixPath('tests/files/Other Comms.ipynb')), c...
FAILED tests/test_cli.py::test_mult[True-True-input_names1] - AssertionError: assert [call(PosixPath('tests/files/Other Comms.ipynb')), c...
FAILED tests/test_cli.py::test_mult[True-True-input_names2] - AssertionError: assert [call(PosixPath('tests/files/Other Comms.ipynb')), c...
FAILED tests/test_cli.py::test_output[thing-False-input_names0] - AssertionError: assert [call(PosixPath('/builddir/build/BUILD/python-nbclie...
FAILED tests/test_cli.py::test_output[thing-False-input_names1] - AssertionError: assert [call(PosixPath('/builddir/build/BUILD/python-nbclie...
FAILED tests/test_cli.py::test_output[thing-True-input_names0] - AssertionError: assert [call(PosixPath('tests/files/Other Comms.ipynb')), c...
FAILED tests/test_cli.py::test_output[thing-True-input_names1] - AssertionError: assert [call(PosixPath('tests/files/Other Comms.ipynb')), c...
FAILED tests/test_cli.py::test_output[thing.ipynb-False-input_names0] - AssertionError: assert [call(PosixPath('/builddir/build/BUILD/python-nbclie...
FAILED tests/test_cli.py::test_output[thing.ipynb-False-input_names1] - AssertionError: assert [call(PosixPath('/builddir/build/BUILD/python-nbclie...
FAILED tests/test_cli.py::test_output[thing.ipynb-True-input_names0] - AssertionError: assert [call(PosixPath('tests/files/Other Comms.ipynb')), c...
FAILED tests/test_cli.py::test_output[thing.ipynb-True-input_names1] - AssertionError: assert [call(PosixPath('tests/files/Other Comms.ipynb')), c...
FAILED tests/test_cli.py::test_output[{noteboo0     0   140k      0  0:00:01  0:00:01 --:--:--  140k
k_name}-new.ipynb-False-input_names0] - AssertionError: assert [call(PosixPath('/builddir/build/BUILD/python-nbclie...
FAILED tests/test_cli.py::test_output[{notebook_name}-new.ipynb-False-input_names1] - AssertionError: assert [call(PosixPath('/builddir/build/BUILD/python-nbclie...
FAILED tests/test_cli.py::test_output[{notebook_name}-new.ipynb-False-input_names2] - AssertionError: assert [call(PosixPath('/builddir/build/BUILD/python-nbclie...
FAILED tests/test_cli.py::test_output[{notebook_name}-new.ipynb-True-input_names0] - AssertionError: assert [call(PosixPath('tests/files/Other Comms.ipynb')), c...
FAILED tests/test_cli.py::test_output[{notebook_name}-new.ipynb-True-input_names1] - AssertionError: assert [call(PosixPath('tests/files/Other Comms.ipynb')), c...
FAILED tests/test_cli.py::test_output[{notebook_name}-new.ipynb-True-input_names2] - AssertionError: assert [call(PosixPath('tests/files/Other Comms.ipynb')), c...
============ 26 failed, 101 passed, 61 warnings in 97.33s (0:01:37) ============

All failures are very similar so I copied output of the last one only. Basically, this assert:

assert path_open.mock_calls[::3] == [call(p) for p in paths]

It is not True because in Python 3.13 there are additional items in path_open.mock_call: call().close() (always) and call().__exit__(None, None, None) (in some cases).

Would it make sense to reimplement the assert so it checks whether [call(p) for p in paths] is a subset of path_open.mock_calls?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions