File tree Expand file tree Collapse file tree 1 file changed +23
-9
lines changed Expand file tree Collapse file tree 1 file changed +23
-9
lines changed Original file line number Diff line number Diff line change @@ -231,19 +231,27 @@ def assert_plugin_disabled(self, msg):
231
231
"""Assert that our plugin was disabled during an operation."""
232
232
# self.run_django_coverage will raise PluginDisabled if the plugin
233
233
# was disabled.
234
- with self .assertRaises (PluginDisabled ):
235
- yield
236
- stderr = self .stderr ()
234
+ # Coverage.py 6.0 made the warnings real warnings, so we have to adapt
235
+ # how we test the warnings based on the version.
236
+ if coverage .version .version_info >= (6 , 0 ):
237
+ import coverage .exceptions as cov_exc
238
+ ctxmgr = self .assertWarns (cov_exc .CoverageWarning )
239
+ else :
240
+ ctxmgr = nullcontext ()
241
+ with ctxmgr as cw :
242
+ with self .assertRaises (PluginDisabled ):
243
+ yield
244
+
245
+ if cw is not None :
246
+ warn_text = "\n " .join (str (w .message ) for w in cw .warnings )
247
+ else :
248
+ warn_text = self .stderr ()
237
249
self .assertIn (
238
- "Coverage.py warning: "
239
250
"Disabling plug-in 'django_coverage_plugin.DjangoTemplatePlugin' "
240
251
"due to an exception:" ,
241
- stderr
242
- )
243
- self .assertIn (
244
- "DjangoTemplatePluginException: " + msg ,
245
- stderr
252
+ warn_text
246
253
)
254
+ self .assertIn ("DjangoTemplatePluginException: " + msg , warn_text )
247
255
248
256
249
257
def squashed (s ):
@@ -282,3 +290,9 @@ def test_thing(self):
282
290
class PluginDisabled (Exception ):
283
291
"""Raised if we find that our plugin has been disabled."""
284
292
pass
293
+
294
+
295
+ @contextlib .contextmanager
296
+ def nullcontext ():
297
+ """For when we need a context manager to do nothing."""
298
+ yield None
You can’t perform that action at this time.
0 commit comments