When I use fp = tmpdir.join("hello.txt")
in pytest, does pytest actually create a file in my temp directory or it creates only when I write fp.write("hello")
?
No, pytest
will not create the file until you actually write to it. Under the hood, as mentioned in the documentation, tmpdir
uses py.path. When you call join it will lazily get the new path, meaning it does not exist until you actually write something to it.