Efren Efren - 1 month ago 6
Python Question

os.path.join fails with "TypeError: object of type 'LocalPath' has no len()"

This error appeared when trying to use the 'tmpdir' in a pytest test.


TypeError: object of type 'LocalPath' has no len()

Answer

'tmpdir' is of type <class 'py._path.local.LocalPath'>, just wrap 'tmpdir' in a string when passing to os.path.join

eg:

os.path.join(str(tmpdir, 'my_test_file.txt')

Comments