Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Temporary directory - tmpdir

  • tmpdir
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)
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