Description
Bug report
pathlib._Base_PathTest.test_is_char_device_true
is skipped unless Path("/dev/null").exists()
evaluates to True
:
cpython/Lib/test/test_pathlib.py
Lines 2591 to 2600 in 376137f
I think the assumption is that if that filepath exists, the test must be running on a Posix machine (/dev/null
isn't a special path in any way on Windows). However, this isn't necessarily true! On my Windows machine (to my surprise), I do have a /dev/null
directory:
>>> import pathlib
>>> P = pathlib.Path("/dev/null")
>>> P.exists()
True
>>> P.absolute()
WindowsPath('C:/dev/null')
Why do I have a /dev/null
path on my machine? I'm not sure, but I suspect I probably ran some script at some point that didn't have proper support for Windows, and it created a /dev/null
folder for me instead of erroring out when it found that my machine didn't have one. Looks like I've got some weird mypy caches in there or something.
Anyway, the test should be more resilient to weird edge cases like this; it currently fails on my machine:
Results of running `python -m test test_pathlib` on my machine
======================================================================
FAIL: test_is_char_device_true (test.test_pathlib.PathSubclassTest.test_is_char_device_true)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\alexw\coding\cpython\Lib\test\test_pathlib.py", line 2596, in test_is_char_device_true
self.assertTrue(P.is_char_device())
AssertionError: False is not true
======================================================================
FAIL: test_is_char_device_true (test.test_pathlib.PathTest.test_is_char_device_true)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\alexw\coding\cpython\Lib\test\test_pathlib.py", line 2596, in test_is_char_device_true
self.assertTrue(P.is_char_device())
AssertionError: False is not true
======================================================================
FAIL: test_is_char_device_true (test.test_pathlib.WindowsPathTest.test_is_char_device_true)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\alexw\coding\cpython\Lib\test\test_pathlib.py", line 2596, in test_is_char_device_true
self.assertTrue(P.is_char_device())
AssertionError: False is not true
----------------------------------------------------------------------
Ran 595 tests in 2.706s
FAILED (failures=3, skipped=191)
test test_pathlib failed
test_pathlib failed (3 failures)
== Tests result: FAILURE ==
Maybe the test should just be skipped on Windows?
Your environment
- CPython versions tested on:
main
@ 263abd3- 3.11
- Operating system and architecture: 64-bit Windows (AMD64)
Linked PRs
- gh-104242: Skip test_is_char_device_true in pathlib test on non posix platform #116904
- gh-104242: Enable test_is_char_device_true in pathlib test on all platform #116983
- [3.12] gh-104242: Enable test_is_char_device_true in pathlib test on … #117277
- [3.11] [3.12] gh-104242: Enable test_is_char_device_true in pathlib test on all platform (GH-116983) (GH-117277) #117280