Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with Python 3.13 #316

Open
frenzymadness opened this issue Jul 3, 2024 · 1 comment · May be fixed by #317
Open

Compatibility with Python 3.13 #316

frenzymadness opened this issue Jul 3, 2024 · 1 comment · May be fixed by #317

Comments

@frenzymadness
Copy link
Contributor

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?

frenzymadness added a commit to frenzymadness/nbclient that referenced this issue Jul 3, 2024
There are more calls in 3.13 than in previous versions
so the tests are now more permissive.

Fixes: jupyter#316
@frenzymadness frenzymadness linked a pull request Jul 3, 2024 that will close this issue
@frenzymadness
Copy link
Contributor Author

It's not possible to use sets because: TypeError: unhashable type: '_Call' but I have another approach that works but I have no idea whether it's okay for the test.

frenzymadness added a commit to frenzymadness/nbclient that referenced this issue Jul 3, 2024
There are more calls in 3.13 than in previous versions
so the tests are now more permissive.

Fixes: jupyter#316
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant