Search code examples
pythoncode-coveragepants

Is there a way to grab pants code coverage results?


I want to look at the results of code coverage in a script that then decides whether it is ok for the user to proceed. Does pants have this functionality? Is there any way to do this other than piping it into an external file and parsing?

Right now it prints everything to stdout, which isn't the best for what I'm trying to do. On top of that, when I do pipe to another file, I don't get the actual code coverage, just the compilation pants does up the it, like so

    09:55:36 00:00 [main]
               (To run a reporting server: ./pants server)
09:55:36 00:00   [setup]
09:55:37 00:01     [parse]
               Executing tasks in goals: bootstrap -> imports -> unpack-jars -> jvm-platform-validate -> deferred-sources -> gen -> resolve -> resources -> pyprep -> compile -> test
09:55:37 00:01   [bootstrap]
09:55:37 00:01     [substitute-aliased-targets]
09:55:37 00:01     [jar-dependency-management]
09:55:37 00:01     [bootstrap-jvm-tools]
09:55:37 00:01     [provide-tools-jar]
09:55:37 00:01   [imports]
09:55:37 00:01     [ivy-imports]
09:55:37 00:01   [unpack-jars]
09:55:37 00:01     [unpack-jars]
09:55:37 00:01   [jvm-platform-validate]
09:55:37 00:01     [jvm-platform-validate]
09:55:37 00:01   [deferred-sources]
09:55:37 00:01     [deferred-sources]
09:55:37 00:01   [gen]
09:55:37 00:01     [antlr-java]
09:55:37 00:01     [antlr-py]
09:55:37 00:01     [jaxb]
09:55:37 00:01     [protoc]
09:55:37 00:01     [ragel]
09:55:37 00:01     [thrift-java]
09:55:37 00:01     [thrift-py]
09:55:37 00:01     [wire]
09:55:37 00:01     [go-thrift]
09:55:37 00:01   [resolve]
09:55:37 00:01     [ivy]
09:55:37 00:01     [coursier]
09:55:37 00:01     [go]
09:55:37 00:01   [resources]
09:55:37 00:01     [prepare]
09:55:37 00:01     [services]
09:55:37 00:01   [pyprep]
09:55:37 00:01     [interpreter]
09:55:37 00:01     [build-local-dists]
09:55:37 00:01     [requirements]
09:55:37 00:01     [sources]
09:55:37 00:01   [compile]
09:55:37 00:01     [compile-jvm-prep-command]
09:55:37 00:01       [jvm_prep_command]
09:55:37 00:01     [compile-prep-command]
09:55:37 00:01     [compile]
09:55:37 00:01     [zinc]
09:55:37 00:01     [jvm-dep-check]
09:55:37 00:01     [go]
09:55:37 00:01   [test]
09:55:37 00:01     [test-jvm-prep-command]
09:55:37 00:01       [jvm_prep_command]
09:55:37 00:01     [test-prep-command]
09:55:37 00:01     [test]
09:55:37 00:01     [pytest-prep]
09:55:38 00:02     [pytest]
                   tests/python/pom_manager:all                                        .....   SUCCESS
                   tests/python/pom_manager:pom_util_test                              .....   SUCCESS
                   tests/python/pom_manager:pom_manager_test                           .....   SUCCESS
                   tests/python/pom_manager:pom_worker_test                            .....   SUCCESS
                   tests/python/pom_manager:pom_validator_test                         .....   SUCCESS
                   tests/python/pom_manager:lc_util_test                               .....   SUCCESS
09:55:38 00:02     [junit]
09:55:38 00:02     [go]
               Waiting for background workers to finish.
09:55:38 00:02   [complete]
               SUCCESS

Solution

  • For anyone who comes across this issue later, I found out that pants stores an html file of all the code coverage which was easy enough to parse.