Repository navigation
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
| def test_is_char_device_true(self): | |
| # Under Unix, /dev/null should generally be a char device. | |
| P = self.cls('/dev/null') | |
| if not P.exists(): | |
| self.skipTest("/dev/null required") | |
| self.assertTrue(P.is_char_device()) | |
| self.assertFalse(P.is_block_device()) | |
| self.assertFalse(P.is_file()) | |
| self.assertIs(self.cls('/dev/null\udfff').is_char_device(), False) | |
| self.assertIs(self.cls('/dev/null\x00').is_char_device(), False) |
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
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsDone
Activity
terryjreedy commentedon May 6, 2023
The test seems to be testing that the system meets certain assumptions rather than the behavior of pathlib. It even says that /dev/null usually is a char device, but fails if, unusually, it is not. On Windows, /dev/null is usually absent, unless it is not.
CAM-Gerlach commentedon May 6, 2023
Instead of skipping a test on a specific platform, it seems it might be more robust to instead skip if the platform isn't POSIX, i.e. if
os.nameis notposix?pythongh-104242: Skip test_is_char_device_true in pathlib test on non…
pythongh-104242: Enable test_is_char_device_true in pathlib test on a…
gh-104242: Enable test_is_char_device_true in pathlib test on all pla…
[3.12] pythongh-104242: Enable test_is_char_device_true in pathlib te…
[3.12] gh-104242: Enable test_is_char_device_true in pathlib test on …
[3.12] pythongh-104242: Enable test_is_char_device_true in pathlib te…
[3.11] gh-104242: Enable test_is_char_device_true in pathlib test on …
Squashed commit of the following:
Squashed commit of the following:
pythongh-104242: Enable test_is_char_device_true in pathlib test on a…