1919import pytest
2020import os
2121import shutil
22+ import signal
2223import sys
2324import webapp2
2425
@@ -37,21 +38,34 @@ def capture():
3738 finally :
3839 sys .stdout , sys .stderr = oldout , olderr
3940
41+ class RefreshHandler (webapp2 .RequestHandler ):
4042
41- class TestRunnerHandler (webapp2 .RequestHandler ):
42-
43- def get (self ):
44- # Set up test directory.
45- if os .path .isdir ('tests' ):
43+ def get (self ):
44+ # Set up test directory.
45+ if os .path .isdir ('tests' ):
4646 shutil .rmtree ('tests' )
47- os .mkdir ('tests' )
47+ os .mkdir ('tests' )
4848
49- # Refresh the tests from cloud storage.
50- bucket = storage .Client ().get_bucket (GCLOUD_STORAGE_BUCKET )
51- blob_iter = bucket .list_blobs ()
52- for blob in blob_iter :
49+ # Refresh the tests from cloud storage.
50+ bucket = storage .Client ().get_bucket (GCLOUD_STORAGE_BUCKET )
51+ blob_iter = bucket .list_blobs ()
52+ for blob in blob_iter :
5353 blob .download_to_filename ('tests/%s' % blob .name )
5454
55+ # Tell Gunicorn to refresh this process so that our modules
56+ # will be refreshed with the new files. The gunicorn process
57+ # is stored in gunicorn_pid.txt.
58+ with open ('gunicorn_pid.txt' ) as f :
59+ for line in f :
60+ pid = int (line )
61+
62+ os .kill (pid , signal .SIGHUP )
63+
64+
65+
66+ class TestRunnerHandler (webapp2 .RequestHandler ):
67+
68+ def get (self ):
5569 # Run the tests.
5670 with capture () as outf :
5771 result = pytest .main (['tests' ])
@@ -62,6 +76,9 @@ def get(self):
6276 self .response .status = 500
6377
6478
79+
80+
6581app = webapp2 .WSGIApplication ([
66- ('/' , TestRunnerHandler ),
82+ ('/refresh' , RefreshHandler ),
83+ ('/test' , TestRunnerHandler ),
6784], debug = True )
0 commit comments