Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

test_pathlib can fail on Windows if a /dev/null folder exists #104242

Copy link
Copy link
Closed
@AlexWaygood

Description

@AlexWaygood
Issue body actions

Bug report

pathlib._Base_PathTest.test_is_char_device_true is skipped unless Path("/dev/null").exists() evaluates to True:

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:
  • Operating system and architecture: 64-bit Windows (AMD64)

Linked PRs

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.