pathlib Path and py.test LocalPath

大憨熊 提交于 2019-12-05 06:22:10

That last one (wrapping) should work, I suspect you actually test all of these in one py.test/tox run and that monkey-patch is still in effect (that might explain why it worked at some point, the order of the test files etc matters if you start to change things on global classes).

That this is hard, is because of Path essentially being a generator, that on the fly decides whether you are on Windows or Linux, and creates a WindowsPath resp. PosixPath accordingly.

BDFL Guido van Rossum already indicated in May 2015:

It does sound like subclassing Path should be made easier.

but nothing happened. Support for pathlib in 3.6 within other standard libraries has increased, but pathlib itself still has the same problems.

In case anyone else is researching whether pytest's tmpdir paths play nicely with pathlib.Path:

Using python 3.6.5 and pytest 3.2.1, the code posted in the question works perfectly fine without explicitly casting to str:

from pathlib import Path

def test_tmpdir(tmpdir):
    p = Path(tmpdir) / 'testfile.csv'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!