1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Capture coverage of both pip installed library and python standard library

Discussão em 'Python' iniciado por Stack, Outubro 3, 2024 às 23:12.

  1. Stack

    Stack Membro Participativo

    I am interested in capturing python coverage of both a pip installed package and the python standard library. When I add this code snippet to the beginning of my program, I am able to capture coverage of the standard library.

    import atexit
    import coverage
    cov = coverage.coverage(data_file='tempfile', cover_pylib=True, branch=True)
    cov.start()
    # Register an exist handler that will print coverage
    def exit_handler():
    cov.stop()
    cov.save()

    atexit.register(exit_handler)


    However, when I try to add the name of the package I am interested in as a source argument, only the coverage of that package is captured. ex:

    coverage.coverage(data_file='tempfile', cover_pylib=True, source=["numpy"], branch=True)


    It seems that the cover_pylib and source arguments are exclusive to each other.

    Ideally, I would like to be able to capture the coverage across all packages and the standard library.

    I'd also prefer not to directly take the source code of the package and put it in my working directory since I'd also like to capture coverage of any package the original package depends on.

    Continue reading...

Compartilhe esta Página