Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当我fp = tmpdir.join("hello.txt")在 pytest 中使用时,pytest 实际上是在我的临时目录中创建一个文件还是仅在我编写时才创建fp.write("hello")?
fp = tmpdir.join("hello.txt")
fp.write("hello")
不,pytest在您实际写入文件之前不会创建文件。如文档中所述,在引擎盖下tmpdir使用py.path。当您调用join时,它会懒惰地获取新路径,这意味着它不存在,直到您实际向其写入内容。
pytest
tmpdir