Bug 2275051 - pytest fails to build with Python 3.13: OSError: No username set in the environment & 6 other failed
Summary: pytest fails to build with Python 3.13: OSError: No username set in the envir...
Keywords:
Status: NEW
Alias: None
Product: Fedora
Classification: Fedora
Component: pytest
Version: rawhide
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Thomas Moschny
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: PYTHON3.13
TreeView+ depends on / blocked
 
Reported: 2024-04-15 07:07 UTC by Karolina Surma
Modified: 2024-04-15 07:07 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed:
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Karolina Surma 2024-04-15 07:07:47 UTC
pytest fails to build with Python 3.13.0a6.

=================================== FAILURES ===================================
_________________________ test_get_user_uid_not_found __________________________
[gw3] linux -- Python 3.13.0 /usr/bin/python3

    def getuser():
        """Get the username from the environment or password database.
    
        First try various environment variables, then the password
        database.  This works on Windows as long as USERNAME is set.
        Any failure to find a username raises OSError.
    
        .. versionchanged:: 3.13
            Previously, various exceptions beyond just :exc:`OSError`
            were raised.
        """
    
        for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
            user = os.environ.get(name)
            if user:
                return user
    
        try:
            import pwd
>           return pwd.getpwuid(os.getuid())[0]
E           KeyError: 'getpwuid(): uid not found: -1'

/usr/lib64/python3.13/getpass.py:173: KeyError

The above exception was the direct cause of the following exception:

    @pytest.mark.usefixtures("break_getuser")
    @pytest.mark.skipif(sys.platform.startswith("win"), reason="no os.getuid on windows")
    def test_get_user_uid_not_found():
        """Test that get_user() function works even if the current process's
        user id does not correspond to a valid user (e.g. running pytest in a
        Docker container with 'docker run -u'.
        """
>       assert get_user() is None

testing/test_tmpdir.py:358: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../BUILDROOT/pytest-7.4.3-5.fc41.x86_64/usr/lib/python3.13/site-packages/_pytest/tmpdir.py:211: in get_user
    return getpass.getuser()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

    def getuser():
        """Get the username from the environment or password database.
    
        First try various environment variables, then the password
        database.  This works on Windows as long as USERNAME is set.
        Any failure to find a username raises OSError.
    
        .. versionchanged:: 3.13
            Previously, various exceptions beyond just :exc:`OSError`
            were raised.
        """
    
        for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
            user = os.environ.get(name)
            if user:
                return user
    
        try:
            import pwd
            return pwd.getpwuid(os.getuid())[0]
        except (ImportError, KeyError) as e:
>           raise OSError('No username set in the environment') from e
E           OSError: No username set in the environment

/usr/lib64/python3.13/getpass.py:175: OSError
__________________________ test_excinfo_no_sourcecode __________________________
[gw3] linux -- Python 3.13.0 /usr/bin/python3

    def test_excinfo_no_sourcecode():
        try:
            exec("raise ValueError()")
        except ValueError:
            excinfo = _pytest._code.ExceptionInfo.from_current()
        s = str(excinfo.traceback[-1])
>       assert s == "  File '<string>':1 in <module>\n  ???\n"
E       assert "  File '<str...eadline()))\n" == "  File '<str...ule>\n  ???\n"
E             File '<string>':1 in <module>
E         -   ???
E         +   import sys;exec(eval(sys.stdin.readline()))

/builddir/build/BUILD/pytest-7.4.3/testing/code/test_excinfo.py:372: AssertionError
________________ TestDoctests.test_doctest_unexpected_exception ________________
[gw2] linux -- Python 3.13.0 /usr/bin/python3

self = <test_doctest.TestDoctests object at 0x7fc17729d090>
pytester = <Pytester PosixPath('/tmp/pytest-of-mockbuild/pytest-0/popen-gw2/test_doctest_unexpected_exception0')>

    def test_doctest_unexpected_exception(self, pytester: Pytester):
        pytester.maketxtfile(
            """
            >>> i = 0
            >>> 0 / i
            2
        """
        )
        result = pytester.runpytest("--doctest-modules")
>       result.stdout.fnmatch_lines(
            [
                "test_doctest_unexpected_exception.txt F *",
                "",
                "*= FAILURES =*",
                "*_ [[]doctest[]] test_doctest_unexpected_exception.txt _*",
                "001 >>> i = 0",
                "002 >>> 0 / i",
                "UNEXPECTED EXCEPTION: ZeroDivisionError*",
                "Traceback (most recent call last):",
                '  File "*/doctest.py", line *, in __run',
                "    *",
                *(
                    (" *^^^^*",)
                    if (3, 11, 0, "beta", 4) > sys.version_info >= (3, 11)
                    else ()
                ),
                '  File "<doctest test_doctest_unexpected_exception.txt[1]>", line 1, in <module>',
                "ZeroDivisionError: division by zero",
                "*/test_doctest_unexpected_exception.txt:2: UnexpectedException",
            ],
            consecutive=True,
        )
E       Failed: nomatch: 'test_doctest_unexpected_exception.txt F *'
E           and: '============================= test session starts =============================='
E           and: 'platform linux -- Python 3.13.0a6, pytest-7.4.3, pluggy-1.3.0'
E           and: 'rootdir: /tmp/pytest-of-mockbuild/pytest-0/popen-gw2/test_doctest_unexpected_exception0'
E           and: 'collected 1 item'
E           and: ''
E       fnmatch: 'test_doctest_unexpected_exception.txt F *'
E          with: 'test_doctest_unexpected_exception.txt F                                  [100%]'
E       exact match: ''
E       fnmatch: '*= FAILURES =*'
E          with: '=================================== FAILURES ==================================='
E       fnmatch: '*_ [[]doctest[]] test_doctest_unexpected_exception.txt _*'
E          with: '_______________ [doctest] test_doctest_unexpected_exception.txt ________________'
E       exact match: '001 >>> i = 0'
E       exact match: '002 >>> 0 / i'
E       fnmatch: 'UNEXPECTED EXCEPTION: ZeroDivisionError*'
E          with: "UNEXPECTED EXCEPTION: ZeroDivisionError('division by zero')"
E       exact match: 'Traceback (most recent call last):'
E       fnmatch: '  File "*/doctest.py", line *, in __run'
E          with: '  File "/usr/lib64/python3.13/doctest.py", line 1378, in __run'
E       fnmatch: '    *'
E          with: '    exec(compile(example.source, filename, "single",'
E       no consecutive match: '  File "<doctest test_doctest_unexpected_exception.txt[1]>", line 1, in <module>'
E          with: '    ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^'

/builddir/build/BUILD/pytest-7.4.3/testing/test_doctest.py:214: Failed
----------------------------- Captured stdout call -----------------------------
============================= test session starts ==============================
platform linux -- Python 3.13.0a6, pytest-7.4.3, pluggy-1.3.0
rootdir: /tmp/pytest-of-mockbuild/pytest-0/popen-gw2/test_doctest_unexpected_exception0
collected 1 item

test_doctest_unexpected_exception.txt F                                  [100%]

=================================== FAILURES ===================================
_______________ [doctest] test_doctest_unexpected_exception.txt ________________
001 >>> i = 0
002 >>> 0 / i
UNEXPECTED EXCEPTION: ZeroDivisionError('division by zero')
Traceback (most recent call last):
  File "/usr/lib64/python3.13/doctest.py", line 1378, in __run
    exec(compile(example.source, filename, "single",
    ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                 compileflags, True), test.globs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<doctest test_doctest_unexpected_exception.txt[1]>", line 1, in <module>
ZeroDivisionError: division by zero
/tmp/pytest-of-mockbuild/pytest-0/popen-gw2/test_doctest_unexpected_exception0/test_doctest_unexpected_exception.txt:2: UnexpectedException
=========================== short test summary info ============================
FAILED test_doctest_unexpected_exception.txt::test_doctest_unexpected_exception.txt
============================== 1 failed in 0.00s ===============================
________________ TestDoctests.test_doctest_linedata_on_property ________________
[gw2] linux -- Python 3.13.0 /usr/bin/python3

self = <test_doctest.TestDoctests object at 0x7fc17717e0d0>
pytester = <Pytester PosixPath('/tmp/pytest-of-mockbuild/pytest-0/popen-gw2/test_doctest_linedata_on_property0')>

    def test_doctest_linedata_on_property(self, pytester: Pytester):
        pytester.makepyfile(
            """
            class Sample(object):
                @property
                def some_property(self):
                    '''
                    >>> Sample().some_property
                    'another thing'
                    '''
                    return 'something'
            """
        )
        result = pytester.runpytest("--doctest-modules")
>       result.stdout.fnmatch_lines(
            [
                "*= FAILURES =*",
                "*_ [[]doctest[]] test_doctest_linedata_on_property.Sample.some_property _*",
                "004 ",
                "005         >>> Sample().some_property",
                "Expected:",
                "    'another thing'",
                "Got:",
                "    'something'",
                "",
                "*/test_doctest_linedata_on_property.py:5: DocTestFailure",
                "*= 1 failed in *",
            ]
        )
E       Failed: nomatch: '*= FAILURES =*'
E           and: '============================= test session starts =============================='
E           and: 'platform linux -- Python 3.13.0a6, pytest-7.4.3, pluggy-1.3.0'
E           and: 'rootdir: /tmp/pytest-of-mockbuild/pytest-0/popen-gw2/test_doctest_linedata_on_property0'
E           and: 'collected 1 item'
E           and: ''
E           and: 'test_doctest_linedata_on_property.py F                                   [100%]'
E           and: ''
E       fnmatch: '*= FAILURES =*'
E          with: '=================================== FAILURES ==================================='
E       fnmatch: '*_ [[]doctest[]] test_doctest_linedata_on_property.Sample.some_property _*'
E          with: '_______ [doctest] test_doctest_linedata_on_property.Sample.some_property _______'
E       exact match: '004 '
E       nomatch: '005         >>> Sample().some_property'
E           and: '005 >>> Sample().some_property'
E           and: 'Expected:'
E           and: "    'another thing'"
E           and: 'Got:'
E           and: "    'something'"
E           and: ''
E           and: '/tmp/pytest-of-mockbuild/pytest-0/popen-gw2/test_doctest_linedata_on_property0/test_doctest_linedata_on_property.py:5: DocTestFailure'
E           and: '=========================== short test summary info ============================'
E           and: 'FAILED test_doctest_linedata_on_property.py::test_doctest_linedata_on_property.Sample.some_property'
E           and: '============================== 1 failed in 0.00s ==============================='
E       remains unmatched: '005         >>> Sample().some_property'

/builddir/build/BUILD/pytest-7.4.3/testing/test_doctest.py:382: Failed
----------------------------- Captured stdout call -----------------------------
============================= test session starts ==============================
platform linux -- Python 3.13.0a6, pytest-7.4.3, pluggy-1.3.0
rootdir: /tmp/pytest-of-mockbuild/pytest-0/popen-gw2/test_doctest_linedata_on_property0
collected 1 item

test_doctest_linedata_on_property.py F                                   [100%]

=================================== FAILURES ===================================
_______ [doctest] test_doctest_linedata_on_property.Sample.some_property _______
004 
005 >>> Sample().some_property
Expected:
    'another thing'
Got:
    'something'

/tmp/pytest-of-mockbuild/pytest-0/popen-gw2/test_doctest_linedata_on_property0/test_doctest_linedata_on_property.py:5: DocTestFailure
=========================== short test summary info ============================
FAILED test_doctest_linedata_on_property.py::test_doctest_linedata_on_property.Sample.some_property
============================== 1 failed in 0.00s ===============================
_______________ test_testdir_makefile_ext_none_raises_type_error _______________
[gw1] linux -- Python 3.13.0 /usr/bin/python3

testdir = <Testdir local('/tmp/pytest-of-mockbuild/pytest-0/popen-gw1/test_testdir_makefile_ext_none_raises_type_error0')>

    def test_testdir_makefile_ext_none_raises_type_error(testdir: Testdir) -> None:
        """For backwards compat #8192"""
>       with pytest.raises(TypeError):
E       Failed: DID NOT RAISE <class 'TypeError'>

/builddir/build/BUILD/pytest-7.4.3/testing/test_legacypath.py:36: Failed
_____________________ test_tmp_path_fallback_uid_not_found _____________________
[gw3] linux -- Python 3.13.0 /usr/bin/python3

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

    @pytest.mark.usefixtures("break_getuser")
    @pytest.mark.skipif(sys.platform.startswith("win"), reason="no os.getuid on windows")
    def test_tmp_path_fallback_uid_not_found(pytester: Pytester) -> None:
        """Test that tmp_path works even if the current process's user id does not
        correspond to a valid user.
        """
    
        pytester.makepyfile(
            """
            def test_some(tmp_path):
                assert tmp_path.is_dir()
        """
        )
        reprec = pytester.inline_run()
>       reprec.assertoutcome(passed=1)
E       AssertionError: ([], [], [<TestReport 'test_tmp_path_fallback_uid_not_found.py::test_some' when='setup' outcome='failed'>])
E       assert {'failed': 1,... 'skipped': 0} == {'failed': 0,... 'skipped': 0}
E         Omitting 1 identical items, use -vv to show
E         Differing items:
E         {'passed': 0} != {'passed': 1}
E         {'failed': 1} != {'failed': 0}
E         Use -v to get more diff

/builddir/build/BUILD/pytest-7.4.3/testing/test_tmpdir.py:348: AssertionError
----------------------------- Captured stdout call -----------------------------
============================= test session starts ==============================
platform linux -- Python 3.13.0a6, pytest-7.4.3, pluggy-1.3.0
rootdir: /tmp/pytest-of-mockbuild/pytest-0/popen-gw3/test_tmp_path_fallback_uid_not_found0
collected 1 item

test_tmp_path_fallback_uid_not_found.py E                                [100%]

==================================== ERRORS ====================================
_________________________ ERROR at setup of test_some __________________________

    def getuser():
        """Get the username from the environment or password database.
    
        First try various environment variables, then the password
        database.  This works on Windows as long as USERNAME is set.
        Any failure to find a username raises OSError.
    
        .. versionchanged:: 3.13
            Previously, various exceptions beyond just :exc:`OSError`
            were raised.
        """
    
        for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
            user = os.environ.get(name)
            if user:
                return user
    
        try:
            import pwd
>           return pwd.getpwuid(os.getuid())[0]
E           KeyError: 'getpwuid(): uid not found: -1'

/usr/lib64/python3.13/getpass.py:173: KeyError

The above exception was the direct cause of the following exception:

    def getuser():
        """Get the username from the environment or password database.
    
        First try various environment variables, then the password
        database.  This works on Windows as long as USERNAME is set.
        Any failure to find a username raises OSError.
    
        .. versionchanged:: 3.13
            Previously, various exceptions beyond just :exc:`OSError`
            were raised.
        """
    
        for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
            user = os.environ.get(name)
            if user:
                return user
    
        try:
            import pwd
            return pwd.getpwuid(os.getuid())[0]
        except (ImportError, KeyError) as e:
>           raise OSError('No username set in the environment') from e
E           OSError: No username set in the environment

/usr/lib64/python3.13/getpass.py:175: OSError
=========================== short test summary info ============================
ERROR test_tmp_path_fallback_uid_not_found.py::test_some - OSError: No userna...
=============================== 1 error in 0.01s ===============================
====== 6 failed, 3410 passed, 33 skipped, 12 xfailed, 7 xpassed in 46.23s ======


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

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

For all our attempts to build pytest with Python 3.13, see:
https://copr.fedorainfracloud.org/coprs/g/python/python3.13/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.13:
https://copr.fedorainfracloud.org/coprs/g/python/python3.13/

Let us know here if you have any questions.

Python 3.13 is planned to be included in Fedora 41.
To make that update smoother, we're building Fedora packages with all pre-releases of Python 3.13.
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.