Skip to content

test_os.test_attributes() fails on Windows #126253

Open

Description

@Eclips4

Bug report

Bug description:

./python -m test -v test_os
======================================================================
FAIL: test_attributes (test.test_os.TestScandir.test_attributes)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\eclips4\programming\cpython\Lib\test\test_os.py", line 5040, in test_attributes
    self.check_entry(entry, 'dir', True, False, False)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\eclips4\programming\cpython\Lib\test\test_os.py", line 5008, in check_entry
    self.assert_stat_equal(entry.stat(),
    ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
                           entry_stat,
                           ^^^^^^^^^^^
                           os.name == 'nt' and not is_symlink)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\eclips4\programming\cpython\Lib\test\test_os.py", line 4967, in assert_stat_equal
    self.assertEqual(getattr(stat1, attr),
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
                     getattr(stat2, attr),
                     ^^^^^^^^^^^^^^^^^^^^^
                     (stat1, stat2, attr))
                     ^^^^^^^^^^^^^^^^^^^^^
AssertionError: 16 != 268435472 : (os.stat_result(st_mode=16895, st_ino=0, st_dev=0, st_nlink=0, st_uid=0, st_gid=0, st_size=0, st_atime=1730398311, st_mtime=1730398311, st_ctime=1730398311), os.stat_result(st_mode=16895, st_ino=5066549580979864, st_dev=2642700522657803134, st_nlink=1, st_uid=0, st_gid=0, st_size=0, st_atime=1730398311, st_mtime=1730398311, st_ctime=1730398311), 'st_file_attributes')

----------------------------------------------------------------------
Ran 367 tests in 16.254s

FAILED (failures=1, skipped=146)
test test_os failed
test_os failed (1 failure)

== Tests result: FAILURE ==

1 test failed:
    test_os

Total duration: 21.1 sec
Total tests: run=367 failures=1 skipped=146
Total test files: run=1/1 failed=1
Result: FAILURE

CPython versions tested on:

CPython main branch

Operating systems tested on:

Windows

Linked PRs

Activity

  1. zooba commented on Oct 31, 2024

    @zooba
    Member

    What's your exact OS build number? This function will have been affected by more recent Windows updates, though I've never seen this behaviour before.

  2. Eclips4 commented on Nov 1, 2024

    @Eclips4
    MemberAuthor

    What's your exact OS build number?

    Not that familiar with Windows so not sure what do you mean

    PS C:\Users\eclips4> (Get-ComputerInfo).WindowsBuildLabEx
    26100.1.amd64fre.ge_release.240331-1435
    

    FWIW, this is a Windows 11 which I downloaded two days ago. So, yes, this build should be pretty new.

  3. zooba commented on Nov 11, 2024

    @zooba
    Member

    Okay, so I have the same build and it doesn't repro here, but I noticed that 268435472 = 0x10000010 which is 16 plus an invalid bit. So my guess is that the API underlying the regular stat() call is not filtering out unknown bits and your file system is somehow deciding to return one.

    Not sure what the best approach here would be. There's a FILE_ATTRIBUTE_VALID_FLAGS constant but it changes with our build settings. Masking inside stat would clear out the extra bit, but if it ever became meaningful then we'd need to update Python to see it. We can probably filter the test quite reasonably to mask with 0x0000FFFF first (any actual use of this field should be checking for certain bits, so the extra one isn't an issue), so maybe that's good enough here?

  4. vstinner commented on Mar 24, 2026

    @vstinner
    Member

    I can reproduce the issue on Windows 11 version 24H2 (Windows-11-10.0.26100-SP0 says the platform module) on a NTFS filesystem.

    Example:

    import os
    dirname = "tmpdir"
    os.mkdir(dirname)
    entry = {entry.name: entry for entry in os.scandir()}[dirname]
    st1 = entry.stat()
    st2 = os.stat(dirname)
    os.rmdir(dirname)
    print("os.scandir() stat:", hex(st1.st_file_attributes))
    print("os.stat():", hex(st2.st_file_attributes))

    Output:

    os.scandir() stat: 0x10
    os.stat(): 0x10000010
    

    Or test_os failure:

    C:\victor\python\main>python -m test test_os.test_os -m test_attributes -v
    
    == CPython 3.15.0a7+ (heads/pr/146347-dirty:d0830f8f8f9, Mar 24 2026, 00:56:18) [MSC v.1950 64 bit (AMD64)]
    == Windows-11-10.0.26100-SP0 little-endian
    == Python build: debug
    == cwd: C:\victor\python\main\build\test_python_worker_8096æ
    (...)
    
    FAIL: test_attributes (test.test_os.test_os.TestScandir.test_attributes)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "C:\victor\python\main\Lib\test\test_os\test_os.py", line 4885, in test_attributes
        self.check_entry(entry, 'dir', True, False, False)
        ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\victor\python\main\Lib\test\test_os\test_os.py", line 4853, in check_entry
        self.assert_stat_equal(entry.stat(),
        ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
                               entry_stat,
                               ^^^^^^^^^^^
                               os.name == 'nt' and not is_symlink)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\victor\python\main\Lib\test\test_os\test_os.py", line 4812, in assert_stat_equal
        self.assertEqual(getattr(stat1, attr),
        ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
                         getattr(stat2, attr),
                         ^^^^^^^^^^^^^^^^^^^^^
                         (stat1, stat2, attr))
                         ^^^^^^^^^^^^^^^^^^^^^
    AssertionError: 16 != 268435472 : (os.stat_result(st_mode=16895, st_ino=0, st_dev=0, st_nlink=0, st_uid=0, st_gid=0, st_size=0, st_atime=1774264899, st_mtime=1774264899, st_ctime=1774264899), os.stat_result(st_mode=16895, st_ino=12103423998593687, st_dev=10298252993199238233, st_nlink=1, st_uid=0, st_gid=0, st_size=0, st_atime=1774264899, st_mtime=1774264899, st_ctime=1774264899), 'st_file_attributes')
    
  5. changed the title [-]``test_os`` fails on Windows[/-] [+]``test_os.test_attributes()`` fails on Windows[/+] on Mar 24, 2026
  6. vstinner commented on Mar 24, 2026

    @vstinner
    Member

    I found multiple articles saying that 0x10000000 means "directory" in "(DOS) file attribute" of NTFS:

    But this constant is not listed in File Attribute Constants documentation.

  7. added a commit that references this issue on Sep 16, 2026
  8. added a commit that references this issue on Nov 4, 2026
  9. hugovk commented on Nov 4, 2026

    @hugovk
    Member

    This is now showing up on this tier 1 worker after a reboot:

    (cc @zware)

    FAIL: test_attributes (test.test_os.test_os.TestScandir.test_attributes)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "C:\Users\buildworker\buildarea\3.x.ware-win11-arm64\build\Lib\test\test_os\test_os.py", line 5108, in test_attributes
        self.check_entry(entry, 'dir', True, False, False)
        ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\buildworker\buildarea\3.x.ware-win11-arm64\build\Lib\test\test_os\test_os.py", line 5076, in check_entry
        self.assert_stat_equal(entry.stat(),
        ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
                               entry_stat,
                               ^^^^^^^^^^^
                               os.name == 'nt' and not is_symlink)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\buildworker\buildarea\3.x.ware-win11-arm64\build\Lib\test\test_os\test_os.py", line 5035, in assert_stat_equal
        self.assertEqual(getattr(stat1, attr),
        ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
                         getattr(stat2, attr),
                         ^^^^^^^^^^^^^^^^^^^^^
                         (stat1, stat2, attr))
                         ^^^^^^^^^^^^^^^^^^^^^
    AssertionError: 16 != 268435472 : (os.stat_result(st_mode=16895, st_ino=0, st_dev=0, st_nlink=0, st_uid=0, st_gid=0, st_size=0, st_atime=1793728813, st_mtime=1793728813, st_ctime=1793728813), os.stat_result(st_mode=16895, st_ino=19421773393521866, st_dev=6923181900724247706, st_nlink=1, st_uid=0, st_gid=0, st_size=0, st_atime=1793728813, st_mtime=1793728813, st_ctime=1793728813), 'st_file_attributes')

    There's a pending PR at #156305.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-windowstestsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions