Skip to content

Python 3.15 support #14524

Description

@befeleme

[heads up] AssertionError in test_dont_write_bytecode and leaking deprecation warnings with Python 3.15.0b1

In Fedora Linux we are building packages with Python 3.15. While pytest itself builds fine and we have successfully used it for many dependent packages, its own test suite doesn't pass the run.

There are two issues with Python 3.15.0b1, one actual AssertionError and 38 deprecation warnings leaking from ptyprocess, treated as errors.
We have pytest 9.0.3, the first failure is reproducible on current main with tox -e py315.
The deprecation warnings appear only in our downstream build, I couldn't reproduce with the current main nor 9.0.3 tag.

_________________ TestRewriteOnImport.test_dont_write_bytecode _________________
[gw3] linux -- Python 3.15.0 /usr/bin/python3

self = <test_assertrewrite.TestRewriteOnImport object at 0x7fa98bbffdf0>
pytester = <Pytester PosixPath('/tmp/pytest-of-mockbuild/pytest-0/popen-gw3/test_dont_write_bytecode0')>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7fa988ff4750>

    def test_dont_write_bytecode(self, pytester: Pytester, monkeypatch) -> None:
        monkeypatch.delenv("PYTHONPYCACHEPREFIX", raising=False)
    
        pytester.makepyfile(
            """
            import os
            def test_no_bytecode():
                assert "__pycache__" in __cached__
                assert not os.path.exists(__cached__)
                assert not os.path.exists(os.path.dirname(__cached__))"""
        )
        monkeypatch.setenv("PYTHONDONTWRITEBYTECODE", "1")
>       assert pytester.runpytest_subprocess().ret == 0
E       AssertionError: assert <ExitCode.TESTS_FAILED: 1> == 0
E        +  where <ExitCode.TESTS_FAILED: 1> = <RunResult ret=1 len(stdout.lines)=19 len(stderr.lines)=0 duration=0.30s>.ret
E        +    where <RunResult ret=1 len(stdout.lines)=19 len(stderr.lines)=0 duration=0.30s> = runpytest_subprocess()
E        +      where runpytest_subprocess = <Pytester PosixPath('/tmp/pytest-of-mockbuild/pytest-0/popen-gw3/test_dont_write_bytecode0')>.runpytest_subprocess

/builddir/build/BUILD/pytest-9.0.3-build/pytest-9.0.3/testing/test_assertrewrite.py:1090: AssertionError
----------------------------- Captured stdout call -----------------------------
running: /usr/bin/python3 -mpytest --basetemp=/tmp/pytest-of-mockbuild/pytest-0/popen-gw3/test_dont_write_bytecode0/runpytest-0
     in: /tmp/pytest-of-mockbuild/pytest-0/popen-gw3/test_dont_write_bytecode0
============================= test session starts ==============================
platform linux -- Python 3.15.0b1, pytest-9.0.3, pluggy-1.6.0
rootdir: /tmp/pytest-of-mockbuild/pytest-0/popen-gw3/test_dont_write_bytecode0
collected 1 item

test_dont_write_bytecode.py F                                            [100%]

=================================== FAILURES ===================================
_______________________________ test_no_bytecode _______________________________

    def test_no_bytecode():
>       assert "__pycache__" in __cached__
                                ^^^^^^^^^^
E       NameError: name '__cached__' is not defined

test_dont_write_bytecode.py:3: NameError
_______________________ TestTrialUnittest.test_trial_pdb _______________________
[gw2] linux -- Python 3.15.0 /usr/bin/python3

self = <test_unittest.TestTrialUnittest object at 0x7f126977c2b0>
pytester = <Pytester PosixPath('/tmp/pytest-of-mockbuild/pytest-0/popen-gw2/test_trial_pdb0')>

    def test_trial_pdb(self, pytester: Pytester) -> None:
        p = pytester.makepyfile(
            """
            from twisted.trial import unittest
            import pytest
            class TC(unittest.TestCase):
                def test_hello(self):
                    assert 0, "hellopdb"
        """
        )
>       child = pytester.spawn_pytest(str(p))
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

/builddir/build/BUILD/pytest-9.0.3-build/pytest-9.0.3/testing/test_unittest.py:617: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/builddir/build/BUILD/pytest-9.0.3-build/BUILDROOT/usr/lib/python3.15/site-packages/_pytest/pytester.py:1531: in spawn_pytest
    return self.spawn(cmd, expect_timeout=expect_timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/builddir/build/BUILD/pytest-9.0.3-build/BUILDROOT/usr/lib/python3.15/site-packages/_pytest/pytester.py:1545: in spawn
    child = pexpect.spawn(cmd, logfile=logfile, timeout=expect_timeout)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/usr/lib/python3.15/site-packages/pexpect/pty_spawn.py:205: in __init__
    self._spawn(command, args, preexec_fn, dimensions)
/usr/lib/python3.15/site-packages/pexpect/pty_spawn.py:303: in _spawn
    self.ptyproc = self._spawnpty(self.args, env=self.env,
/usr/lib/python3.15/site-packages/pexpect/pty_spawn.py:315: in _spawnpty
    return ptyprocess.PtyProcess.spawn(args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/usr/lib/python3.15/site-packages/ptyprocess/ptyprocess.py:230: in spawn
    pid, fd = pty.fork()
              ^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

    def fork():
        """fork() -> (pid, master_fd)
        Fork and make the child a session leader with a controlling terminal."""
    
        try:
>           pid, fd = os.forkpty()
                      ^^^^^^^^^^^^
E           DeprecationWarning: This process (pid=1140) is multi-threaded, use of forkpty() may lead to deadlocks in the child.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions