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):
231231 """Assert that our plugin was disabled during an operation."""
232232 # self.run_django_coverage will raise PluginDisabled if the plugin
233233 # 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 ()
237249 self .assertIn (
238- "Coverage.py warning: "
239250 "Disabling plug-in 'django_coverage_plugin.DjangoTemplatePlugin' "
240251 "due to an exception:" ,
241- stderr
242- )
243- self .assertIn (
244- "DjangoTemplatePluginException: " + msg ,
245- stderr
252+ warn_text
246253 )
254+ self .assertIn ("DjangoTemplatePluginException: " + msg , warn_text )
247255
248256
249257def squashed (s ):
@@ -282,3 +290,9 @@ def test_thing(self):
282290class PluginDisabled (Exception ):
283291 """Raised if we find that our plugin has been disabled."""
284292 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