@@ -158,19 +158,26 @@ class Meta:
158
158
bulk_size = 0
159
159
autocommit = True
160
160
161
- with warnings .catch_warnings (record = True ) as w :
161
+ with warnings .catch_warnings (record = True ) as rec_warnings :
162
162
warnings .simplefilter ("always" )
163
- try :
163
+ # Server defined in the client is invalid, we're testing
164
+ # the warning only.
165
+ with self .assertRaises (ConnectionError ):
164
166
WarnBulkSizeZero (time = 159 , server_name = 'us.east-1' )
165
- except ConnectionError :
166
- # Server defined in the client is invalid, we're testing
167
- # the warning only.
168
- pass
169
- self .assertEqual (len (w ), 1 ,
170
- '{} call should have generated one warning.'
171
- .format (WarnBulkSizeZero ))
172
- self .assertIn ('forced to 1' , str (w [- 1 ].message ),
173
- 'Warning message did not contain "forced to 1".' )
167
+
168
+ self .assertGreaterEqual (
169
+ len (rec_warnings ), 1 ,
170
+ '{} call should have generated one warning.'
171
+ 'Actual generated warnings: {}' .format (
172
+ WarnBulkSizeZero , '\n ' .join (map (str , rec_warnings ))))
173
+
174
+ expected_msg = (
175
+ 'Definition of bulk_size in WarnBulkSizeZero forced to 1, '
176
+ 'was less than 1.' )
177
+
178
+ self .assertIn (expected_msg , list (w .message .args [0 ]
179
+ for w in rec_warnings ),
180
+ 'Warning message did not contain "forced to 1".' )
174
181
175
182
def testWarnBulkSizeNoEffect (self ):
176
183
"""
@@ -184,11 +191,24 @@ class Meta:
184
191
bulk_size = 5
185
192
autocommit = False
186
193
187
- with warnings .catch_warnings (record = True ) as w :
194
+ with warnings .catch_warnings (record = True ) as rec_warnings :
188
195
warnings .simplefilter ("always" )
189
196
WarnBulkSizeNoEffect (time = 159 , server_name = 'us.east-1' )
190
- self .assertEqual (len (w ), 1 ,
191
- '{} call should have generated one warning.'
192
- .format (WarnBulkSizeNoEffect ))
193
- self .assertIn ('has no affect' , str (w [- 1 ].message ),
194
- 'Warning message did not contain "has not affect".' )
197
+
198
+ self .assertGreaterEqual (
199
+ len (rec_warnings ), 1 ,
200
+ '{} call should have generated one warning.'
201
+ 'Actual generated warnings: {}' .format (
202
+ WarnBulkSizeNoEffect , '\n ' .join (map (str , rec_warnings ))))
203
+
204
+ expected_msg = (
205
+ 'Definition of bulk_size in WarnBulkSizeNoEffect has no affect '
206
+ 'because autocommit is false.' )
207
+
208
+ self .assertIn (expected_msg , list (w .message .args [0 ]
209
+ for w in rec_warnings ),
210
+ 'Warning message did not contain the expected_msg.' )
211
+
212
+
213
+ if __name__ == '__main__' :
214
+ unittest .main ()
0 commit comments