Exemple #1
0
 def test_stdout(self):
     fake = FakeReporter(output="Hello!\n")
     msgs = []
     render_report("-", fake, [pytest, "coverage"], msgs.append)
     assert fake.morfs == [pytest, "coverage"]
     assert self.stdout() == "Hello!\n"
     assert not msgs
Exemple #2
0
 def test_exception(self):
     fake = FakeReporter(error=True)
     msgs = []
     with pytest.raises(CoverageException, match="You asked for it!"):
         render_report("output.txt", fake, [], msgs.append)
     assert self.stdout() == ""
     self.assert_doesnt_exist("output.txt")
     assert not msgs
Exemple #3
0
 def test_file(self):
     fake = FakeReporter(output="Gréètings!\n")
     msgs = []
     render_report("output.txt", fake, [], msgs.append)
     assert self.stdout() == ""
     with open("output.txt", "rb") as f:
         assert f.read().rstrip() == b"Gr\xc3\xa9\xc3\xa8tings!"
     assert msgs == ["Wrote fake report file to output.txt"]
    def json_report(self,
                    morfs=None,
                    outfile=None,
                    ignore_errors=None,
                    omit=None,
                    include=None,
                    contexts=None,
                    pretty_print=None,
                    show_contexts=None):
        """Generate a JSON report of coverage results.

        Each module in `morfs` is included in the report.  `outfile` is the
        path to write the file to, "-" will write to stdout.

        See :meth:`report` for other arguments.

        Returns a float, the total percentage covered.

        .. versionadded:: 5.0

        """
        with override_config(self,
                             ignore_errors=ignore_errors,
                             report_omit=omit,
                             report_include=include,
                             json_output=outfile,
                             report_contexts=contexts,
                             json_pretty_print=pretty_print,
                             json_show_contexts=show_contexts):
            return render_report(self.config.json_output, JsonReporter(self),
                                 morfs)
    def xml_report(
        self,
        morfs=None,
        outfile=None,
        ignore_errors=None,
        omit=None,
        include=None,
        contexts=None,
        skip_empty=None,
    ):
        """Generate an XML report of coverage results.

        The report is compatible with Cobertura reports.

        Each module in `morfs` is included in the report.  `outfile` is the
        path to write the file to, "-" will write to stdout.

        See :meth:`report` for other arguments.

        Returns a float, the total percentage covered.

        """
        with override_config(
                self,
                ignore_errors=ignore_errors,
                report_omit=omit,
                report_include=include,
                xml_output=outfile,
                report_contexts=contexts,
                skip_empty=skip_empty,
        ):
            return render_report(self.config.xml_output, XmlReporter(self),
                                 morfs)
Exemple #6
0
    def lcov_report(
        self,
        morfs=None,
        outfile=None,
        ignore_errors=None,
        omit=None,
        include=None,
        contexts=None,
    ):
        """Generate an LCOV report of coverage results.

        Each module in 'morfs' is included in the report. 'outfile' is the
        path to write the file to, "-" will write to stdout.

        See :meth 'report' for other arguments.

        .. versionadded:: 6.3
        """
        with override_config(
                self,
                ignore_errors=ignore_errors,
                report_omit=omit,
                report_include=include,
                lcov_output=outfile,
                report_contexts=contexts,
        ):
            return render_report(self.config.lcov_output, LcovReporter(self),
                                 morfs, self._message)