Temporary directory - 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