pytest temporary files
Pytest has a nice tmp_path
fixture that creates a temporary directory and returs the Path
1:
# content of test_tmp_path.py
CONTENT = "content"
def test_create_file(tmp_path):
d = tmp_path / "sub"
d.mkdir()
p = d / "hello.txt"
p.write_text(CONTENT)
assert p.read_text() == CONTENT
assert len(list(tmp_path.iterdir())) == 1
Nel mezzo del deserto posso dire tutto quello che voglio.
comments powered by Disqus