mwouts / jupytext

Jupyter Notebooks as Markdown Documents, Julia, Python or R scripts
https://jupytext.readthedocs.io
MIT License
6.6k stars 386 forks source link

Python 3.13 compatibility #1242

Closed jamesjer closed 1 month ago

jamesjer commented 3 months ago

With python 3.13.0b2, 2 tests fail like this:

_____________ ERROR at setup of test_cm_config_log_only_if_changed _____________

tmp_path = PosixPath('/tmp/pytest-of-mockbuild/pytest-0/test_cm_config_log_only_if_cha0')

    @pytest.fixture()
    def cwd_tmp_path(tmp_path):
        # Run the whole test from inside tmp_path
>       with tmp_path.cwd():
E       TypeError: 'PosixPath' object does not support the context manager protocol

/builddir/build/BUILD/python-jupytext-1.16.2-build/jupytext-1.16.2/tests/conftest.py:50: TypeError

With python 3.11 and later, this works:

import contextlib

@pytest.fixture()
def cwd_tmp_path(tmp_path):
    # Run the whole test from inside tmp_path
    with contextlib.chdir(tmp_path):
        yield tmp_path
mwouts commented 3 months ago

Thanks @jamesjer for looking into this! That's very helpful. I guess we could code two different fixtures and activate either one depending on the Python version, then?

jamesjer commented 3 months ago

Yes, I guess so. That seems kind of ugly, but I don't have any better ideas.

mwouts commented 2 months ago

I've prepared a PR, and as far as I can tell the suggested workaround seems to work. So far it's tested on the CI up to Python 3.12 as my CI seems to have an other independent issue with 3.13 (https://github.com/jupyterlab/maintainer-tools/issues/242). Thanks @jamesjer anyway, we're getting close!