View response's content in a browser while testing

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
import os, tempfile, subprocess

URL_OPENER = 'xdg-open'

def open_response_content(response):
    """ Saves a response's content to a temporary file and opens it in a
    browser. """
    temp_file = tempfile.NamedTemporaryFile(delete=False)
    temp_file.write(response.content)
    dev_null = open(os.devnull, 'w')
    kwargs = {'stdout': dev_null, 'stderr': dev_null}
    subprocess.Popen([URL_OPENER, temp_file.name], **kwargs)

More like this

  1. Load response.content in browser (for debugging) by tin_nqn 1 year ago
  2. Decorator and context manager to override settings by jezdez 2 years ago
  3. A smart trace() command by aparajita 3 years, 11 months ago
  4. Forcing unit test runner to abort after failed test by simonbun 6 years ago
  5. "Zoom in" on rendered HTML that the test client returns by peterbe 4 years, 1 month ago

Comments

(Forgotten your password?)