This error appeared when trying to use the 'tmpdir' in a pytest test.
TypeError: object of type 'LocalPath' has no len()
'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')
Alternatively you can directly access the string form of LocalPath as an attribute.
os.path.join(tmpdir.strpath, 'my_test_file.txt')
I used to think that using the attribute access meant that you were not casting the object to a string thus being more efficient but I think I am wrong in that assumption however, I like this style a bit better it is easier to write IMHO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With