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

Efren picture Efren · Nov 20, 2014 · Viewed 7.6k times · Source

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

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

Answer

Efren picture Efren · Nov 20, 2014

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

example:

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