Efren Efren - 1 year ago 132
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 Source

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


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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download