@@ -17,11 +17,13 @@ class AppTest:
1717 settings = dict (
1818 PrintConfigAtStartUp = False
1919 )
20+ bufferOutput = True # set to False if you want to run pdb inside a test to debug it.
2021
2122 @classmethod
2223 def setUpClass (cls ):
2324 stdout , stderr = sys .stdout , sys .stderr
24- sys .stdout = sys .stderr = StringIO ()
25+ if cls .bufferOutput :
26+ sys .stdout = sys .stderr = StringIO ()
2527 cls .currentDir = getcwd ()
2628 import webware
2729 webwareDir = webware .__path__ [0 ]
@@ -35,43 +37,55 @@ def setUpClass(cls):
3537 else :
3638 error = None
3739 finally :
38- output = sys .stdout .getvalue ().rstrip ()
39- sys .stdout , sys .stderr = stdout , stderr
40+ if cls .bufferOutput :
41+ output = sys .stdout .getvalue ().rstrip ()
42+ sys .stdout , sys .stderr = stdout , stderr
43+ else :
44+ output = ''
4045 if error :
4146 raise RuntimeError (
4247 'Error setting up application:\n ' + error +
4348 '\n Output was:\n ' + output )
44- if (not output .startswith ('Webware for Python' )
45- or 'Running in development mode' not in output
46- or 'Loading context' not in output ):
47- raise AssertionError (
48- 'Application was not properly started.'
49- ' Output was:\n ' + output )
49+ if cls .bufferOutput :
50+ if (not output .startswith ('Webware for Python' )
51+ or 'Running in development mode' not in output
52+ or 'Loading context' not in output ):
53+ raise AssertionError (
54+ 'Application was not properly started.'
55+ ' Output was:\n ' + output )
5056
5157 @classmethod
5258 def tearDownClass (cls ):
5359 stdout , stderr = sys .stdout , sys .stderr
54- sys .stdout = sys .stderr = StringIO ()
60+ if cls .bufferOutput :
61+ sys .stdout = sys .stderr = StringIO ()
5562 cls .app .shutDown ()
56- output = sys .stdout .getvalue ().rstrip ()
57- sys .stdout , sys .stderr = stdout , stderr
63+ if cls .bufferOutput :
64+ output = sys .stdout .getvalue ().rstrip ()
65+ sys .stdout , sys .stderr = stdout , stderr
66+ else :
67+ output = ''
5868 chdir (cls .currentDir )
59- if output != ('Application is shutting down...\n '
60- 'Application has been successfully shutdown.' ):
69+ if cls . bufferOutput and output != ('Application is shutting down...\n '
70+ 'Application has been successfully shutdown.' ):
6171 raise AssertionError (
6272 'Application was not properly shut down. Output was:\n '
6373 + output )
6474
6575 def setUp (self ):
6676 self .stdout , self .stderr = sys .stdout , sys .stderr
67- sys .stdout = sys .stderr = StringIO ()
77+ if self .bufferOutput :
78+ sys .stdout = sys .stderr = StringIO ()
6879
6980 def tearDown (self ):
70- self .output = sys .stdout .getvalue ().rstrip ()
71- sys .stdout , sys .stderr = self .stdout , self .stderr
81+ if self .bufferOutput :
82+ self .output = sys .stdout .getvalue ().rstrip ()
83+ sys .stdout , sys .stderr = self .stdout , self .stderr
84+ else :
85+ self .output = ''
7286
7387 def run (self , result = None ):
7488 result = super ().run (result ) # pylint: disable=no-member
75- if not result .wasSuccessful () and self .output :
89+ if not result .wasSuccessful () and self .bufferOutput and self . output :
7690 print ("Application output was:" )
7791 print (self .output )
0 commit comments