Bug 2069153 - pytest fails to build with Python 3.11: DeprecationWarning: pathlib.Path.__enter__() is deprecated and scheduled for removal in Python 3.13; Path objects as a context manager is a no-op
Summary: pytest fails to build with Python 3.11: DeprecationWarning: pathlib.Path.__en...
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: pytest
Version: rawhide
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Miro Hrončok
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: PYTHON3.11
TreeView+ depends on / blocked
 
Reported: 2022-03-28 11:33 UTC by Tomáš Hrnčiar
Modified: 2022-03-30 11:33 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2022-03-30 11:33:07 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github pytest-dev pytest pull 9800 0 None Merged Fix CI for Python 3.11 2022-03-29 08:46:02 UTC

Description Tomáš Hrnčiar 2022-03-28 11:33:57 UTC
pytest fails to build with Python 3.11.0a6.

=================================== FAILURES ===================================
______________________ Test_getinitialnodes.test_pkgfile _______________________
[gw0] linux -- Python 3.11.0 /usr/bin/python3

self = <test_collection.Test_getinitialnodes object at 0x7f1ccce9ea90>
pytester = <Pytester PosixPath('/tmp/pytest-of-mockbuild/pytest-0/popen-gw0/test_pkgfile0')>

    def test_pkgfile(self, pytester: Pytester) -> None:
        """Verify nesting when a module is within a package.
        The parent chain should match: Module<x.py> -> Package<subdir> -> Session.
            Session's parent should always be None.
        """
        tmp_path = pytester.path
        subdir = tmp_path.joinpath("subdir")
        x = ensure_file(subdir / "x.py")
        ensure_file(subdir / "__init__.py")
>       with subdir.cwd():

/builddir/build/BUILD/pytest-7.0.1/testing/test_collection.py:663: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = PosixPath('/tmp/pytest-of-mockbuild/pytest-0/popen-gw0/test_pkgfile0')

    def __enter__(self):
        # In previous versions of pathlib, __exit__() marked this path as
        # closed; subsequent attempts to perform I/O would raise an IOError.
        # This functionality was never documented, and had the effect of
        # making Path objects mutable, contrary to PEP 428.
        # In Python 3.9 __exit__() was made a no-op.
        # In Python 3.11 __enter__() began emitting DeprecationWarning.
        # In Python 3.13 __enter__() and __exit__() should be removed.
>       warnings.warn("pathlib.Path.__enter__() is deprecated and scheduled "
                      "for removal in Python 3.13; Path objects as a context "
                      "manager is a no-op",
                      DeprecationWarning, stacklevel=2)
E       DeprecationWarning: pathlib.Path.__enter__() is deprecated and scheduled for removal in Python 3.13; Path objects as a context manager is a no-op

/usr/lib64/python3.11/pathlib.py:887: DeprecationWarning
____________________ test_collect_with_chdir_during_import _____________________
[gw0] linux -- Python 3.11.0 /usr/bin/python3

pytester = <Pytester PosixPath('/tmp/pytest-of-mockbuild/pytest-0/popen-gw0/test_collect_with_chdir_during_import0')>

    def test_collect_with_chdir_during_import(pytester: Pytester) -> None:
        subdir = pytester.mkdir("sub")
        pytester.path.joinpath("conftest.py").write_text(
            textwrap.dedent(
                """
                import os
                os.chdir(%r)
                """
                % (str(subdir),)
            )
        )
        pytester.makepyfile(
            """
            def test_1():
                import os
                assert os.getcwd() == %r
            """
            % (str(subdir),)
        )
>       with pytester.path.cwd():

/builddir/build/BUILD/pytest-7.0.1/testing/test_collection.py:1161: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = PosixPath('/tmp/pytest-of-mockbuild/pytest-0/popen-gw0/test_collect_with_chdir_during_import0')

    def __enter__(self):
        # In previous versions of pathlib, __exit__() marked this path as
        # closed; subsequent attempts to perform I/O would raise an IOError.
        # This functionality was never documented, and had the effect of
        # making Path objects mutable, contrary to PEP 428.
        # In Python 3.9 __exit__() was made a no-op.
        # In Python 3.11 __enter__() began emitting DeprecationWarning.
        # In Python 3.13 __enter__() and __exit__() should be removed.
>       warnings.warn("pathlib.Path.__enter__() is deprecated and scheduled "
                      "for removal in Python 3.13; Path objects as a context "
                      "manager is a no-op",
                      DeprecationWarning, stacklevel=2)
E       DeprecationWarning: pathlib.Path.__enter__() is deprecated and scheduled for removal in Python 3.13; Path objects as a context manager is a no-op

/usr/lib64/python3.11/pathlib.py:887: DeprecationWarning
______________________ test_collect_pyargs_with_testpaths ______________________
[gw0] linux -- Python 3.11.0 /usr/bin/python3

pytester = <Pytester PosixPath('/tmp/pytest-of-mockbuild/pytest-0/popen-gw0/test_collect_pyargs_with_testpaths0')>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7f1cb7095250>

    def test_collect_pyargs_with_testpaths(
        pytester: Pytester, monkeypatch: MonkeyPatch
    ) -> None:
        testmod = pytester.mkdir("testmod")
        # NOTE: __init__.py is not collected since it does not match python_files.
        testmod.joinpath("__init__.py").write_text("def test_func(): pass")
        testmod.joinpath("test_file.py").write_text("def test_func(): pass")
    
        root = pytester.mkdir("root")
        root.joinpath("pytest.ini").write_text(
            textwrap.dedent(
                """
            [pytest]
            addopts = --pyargs
            testpaths = testmod
        """
            )
        )
        monkeypatch.setenv("PYTHONPATH", str(pytester.path), prepend=os.pathsep)
>       with root.cwd():

/builddir/build/BUILD/pytest-7.0.1/testing/test_collection.py:1197: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = PosixPath('/tmp/pytest-of-mockbuild/pytest-0/popen-gw0/test_collect_pyargs_with_testpaths0')

    def __enter__(self):
        # In previous versions of pathlib, __exit__() marked this path as
        # closed; subsequent attempts to perform I/O would raise an IOError.
        # This functionality was never documented, and had the effect of
        # making Path objects mutable, contrary to PEP 428.
        # In Python 3.9 __exit__() was made a no-op.
        # In Python 3.11 __enter__() began emitting DeprecationWarning.
        # In Python 3.13 __enter__() and __exit__() should be removed.
>       warnings.warn("pathlib.Path.__enter__() is deprecated and scheduled "
                      "for removal in Python 3.13; Path objects as a context "
                      "manager is a no-op",
                      DeprecationWarning, stacklevel=2)
E       DeprecationWarning: pathlib.Path.__enter__() is deprecated and scheduled for removal in Python 3.13; Path objects as a context manager is a no-op

/usr/lib64/python3.11/pathlib.py:887: DeprecationWarning
=========================== short test summary info ============================
SKIPPED [1] testing/test_capture.py:1432: only on windows
SKIPPED [1] testing/test_pathlib.py:432: Windows only
SKIPPED [1] testing/test_tmpdir.py:221: win only
SKIPPED [1] testing/test_config.py:1839: does not work with xdist currently
SKIPPED [1] testing/test_conftest.py:330: only relevant for case insensitive file systems
SKIPPED [1] ../../BUILDROOT/pytest-7.0.1-1.fc37.x86_64/usr/lib/python3.11/site-packages/_pytest/pathlib.py:434: symlinks not supported: [Errno 17] File exists: '/tmp/pytest-of-mockbuild/pytest-0/popen-gw0/test_collect_symlink_dir0/symlink_dir' -> '/tmp/pytest-of-mockbuild/pytest-0/popen-gw0/test_collect_symlink_dir0/dir'
SKIPPED [1] testing/test_unittest.py:1287: could not import 'asynctest': No module named 'asynctest'
SKIPPED [1] testing/test_compat.py:95: couroutine removed
SKIPPED [1] testing/test_faulthandler.py:71: sometimes crashes on CI (#7022)
======= 3 failed, 3127 passed, 9 skipped, 10 xfailed in 82.09s (0:01:22) =======


https://docs.python.org/3.11/whatsnew/3.11.html

For the build logs, see:
https://copr-be.cloud.fedoraproject.org/results/@python/python3.11/fedora-rawhide-x86_64/03846158-pytest/

For all our attempts to build pytest with Python 3.11, see:
https://copr.fedorainfracloud.org/coprs/g/python/python3.11/package/pytest/

Testing and mass rebuild of packages is happening in copr. You can follow these instructions to test locally in mock if your package builds with Python 3.11:
https://copr.fedorainfracloud.org/coprs/g/python/python3.11/

Let us know here if you have any questions.

Python 3.11 is planned to be included in Fedora 37. To make that update smoother, we're building Fedora packages with all pre-releases of Python 3.11.
A build failure prevents us from testing all dependent packages (transitive [Build]Requires), so if this package is required a lot, it's important for us to get it fixed soon.
We'd appreciate help from the people who know this package best, but if you don't want to work on this now, let us know so we can try to work around it on our side.


Note You need to log in before you can comment on or make changes to this bug.