Temporary directory - tmpdir
- tmpdir
examples/tdir/app.py
import json def read(filename): with open(filename) as fh: return json.load(fh) def save(filename, data): with open(filename, 'w') as fh: return json.dump(data, fh)
examples/tdir/test_app.py
import app import os def test_json(tmpdir): tdir = str(tmpdir) print(tdir) data = { 'name' : 'Foo Bar', 'email' : 'foo@bar.com', } filename = os.path.join(tdir, 'temp.json') app.save(filename, data) again = app.read(filename) assert data == again
- Directory location OSX: /private/var/folders/ry/z60xxmw0000gn/T/pytest-of-gabor/pytest-14/test_read0
- Linux: /tmp/pytest-of-gabor/pytest-9/test_json0
- Directory cleanup