Closed
Description
Originally reported by: Jason R. Coombs (BitBucket: jaraco, GitHub: jaraco)
Consider this simple test:
def test_simple(tmpdir):
import os
os.path.join(tmpdir, 'foo')
Invoke that test on Windows in pytest 2.6.4, and you'll get a failure:
============================= test session starts ============================= platform win32 -- Python 3.4.2 -- py-1.4.26 -- pytest-2.6.4
collected 1 items
test_join.py F
================================== FAILURES =================================== _________________________________ test_simple _________________________________
tmpdir = local('C:\\Users\\jaraco\\AppData\\Local\\Temp\\pytest-19\\test_simple0')
def test_simple(tmpdir):
import os
> os.path.join(tmpdir, 'foo')
test_join.py:3:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c:\python\lib\ntpath.py:108: in join
result_drive, result_path = splitdrive(path)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
p = local('C:\\Users\\jaraco\\AppData\\Local\\Temp\\pytest-19\\test_simple0')
def splitdrive(p):
"""Split a pathname into drive/UNC sharepoint and relative path specifiers.
Returns a 2-tuple (drive_or_unc, path); either part may be empty.
If you assign
result = splitdrive(p)
It is always true that:
result[0] + result[1] == p
If the path contained a drive letter, drive_or_unc will contain everything
up to and including the colon. e.g. splitdrive("c:/dir") returns ("c:", "/dir")
If the path contained a UNC path, the drive_or_unc will contain the host name
and share up to but not including the fourth directory separator character.
e.g. splitdrive("//host/computer/dir") returns ("//host/computer", "/dir")
Paths cannot contain both a drive letter and a UNC path.
"""
empty = _get_empty(p)
> if len(p) > 1:
E TypeError: object of type 'LocalPath' has no len()
c:\python\lib\ntpath.py:159: TypeError
========================== 1 failed in 0.07 seconds ===========================
Should LocalPath support join operations or should the tester expect to convert the LocalPath to a str
before invoking join?
Probably the preferred usage is to use the .join()
method on LocalPath, but that's less obvious.