comparison test/test_actions.py @ 5034:4ad465b09cbe

Update test/test_actions.py to work with py.test The test_actions tests use a FieldStorage object to mock form submissions. FieldStorage would usually use the 'QUERY_STRING' environment variable to populate the initial list of MiniFieldStorage values stored within the FieldStorage object, but because there is no 'QUERY_STRING' environment variable when running the test from the commandline it tries to parse sys.argv instead. If any py.test options are used (ie. '--tb=short') then they may end up in the MiniFieldStorage list causing some tests to fail because they were not expecting the extra MiniFieldStorage values. To fix this we explicitly pass an dict with an empty 'QUERY_STRING' value as the FieldStorage environ argument to ensure that the initial MiniFieldStorage list is empty.
author John Kristensen <john@jerrykan.com>
date Thu, 20 Aug 2015 16:30:50 +1000
parents b562df8a5056
children 364c54991861
comparison
equal deleted inserted replaced
5033:63c79c0992ae 5034:4ad465b09cbe
12 def true(*args, **kwargs): 12 def true(*args, **kwargs):
13 return 1 13 return 1
14 14
15 class ActionTestCase(unittest.TestCase): 15 class ActionTestCase(unittest.TestCase):
16 def setUp(self): 16 def setUp(self):
17 self.form = FieldStorage() 17 self.form = FieldStorage(environ={'QUERY_STRING': ''})
18 self.client = MockNull() 18 self.client = MockNull()
19 self.client._ok_message = [] 19 self.client._ok_message = []
20 self.client._error_message = [] 20 self.client._error_message = []
21 self.client.add_error_message = lambda x : add_message( 21 self.client.add_error_message = lambda x : add_message(
22 self.client._error_message, x) 22 self.client._error_message, x)

Roundup Issue Tracker: http://roundup-tracker.org/