def run_bad_plugin(
        self,
        module_name: str,
        plugin_name: str,
        our_error: bool = True,
        excmsg: str | None = None,
        excmsgs: list[str] | None = None,
    ) -> None:
        """Run a file, and see that the plugin failed.

        `module_name` and `plugin_name` is the module and name of the plugin to
        use.

        `our_error` is True if the error reported to the user will be an
        explicit error in our test code, marked with an '# Oh noes!' comment.

        `excmsg`, if provided, is text that must appear in the stderr.

        `excmsgs`, if provided, is a list of messages, one of which must
        appear in the stderr.

        The plugin will be disabled, and we check that a warning is output
        explaining why.

        """
        with pytest.warns(Warning) as warns:
            self.run_plugin(module_name)

        stderr = self.stderr()
        stderr += "".join(str(w.message) for w in warns)
        if our_error:
            # The exception we're causing should only appear once.
            assert stderr.count("# Oh noes!") == 1

        # There should be a warning explaining what's happening, but only one.
        # The message can be in two forms:
        #   Disabling plug-in '...' due to previous exception
        # or:
        #   Disabling plug-in '...' due to an exception:
        print([str(w) for w in warns.list])
        warnings = [w for w in warns.list if issubclass(w.category, CoverageWarning)]
        assert len(warnings) == 1
        warnmsg = str(warnings[0].message)
        assert f"Disabling plug-in '{module_name}.{plugin_name}' due to " in warnmsg

        if excmsg:
            assert excmsg in stderr
        if excmsgs:
            found_exc = any(em in stderr for em in excmsgs)             #  pragma: part covered
            assert found_exc, f"expected one of {excmsgs} in stderr"
Run a file, and see that the plugin failed.

        `module_name` and `plugin_name` is the module and name of the plugin to
        use.

        `our_error` is True if the error reported to the user will be an
        explicit error in our test code, marked with an '# Oh noes!' comment.

        `excmsg`, if provided, is text that must appear in the stderr.

        `excmsgs`, if provided, is a list of messages, one of which must
        appear in the stderr.

        The plugin will be disabled, and we check that a warning is output
        explaining why.

        
tests/test_plugins.py