report not showing sub-process coverage

Issue #644 resolved
Abel Asefa created an issue

Subprocess files are not included in the report

index.py

import coverage
cov = coverage.coverage(data_suffix=True)
cov.start()
import subprocess as sp
from_sub_process = sp.check_output(['python', 'test3.py'])
from_sub_process = str(from_sub_process)
def test_a():
    return "a"
def test_b(character):
    global from_sub_process
    from_sub_process += character
test_b(test_a())
cov.combine()
cov.stop()
cov.save()
cov.html_report()

test3.py

#!C:\python
#test3.py
import sys
print(sys.path)
def ab():
    print("ab")
ab()

Here is my sitecustomize.py

import coverage
coverage.process_startup()

and COVERAGE_PROCESS_START points to the folder where .coverage file is generated

and here is the coverage report Capture.PNG

coverage of test3.py not shown

Comments (9)

  1. Ned Batchelder repo owner

    Thanks for the detailed report!

    Your COVERAGE_PROCESS_START environment variable should be the path to the .coveragerc file, not the path to a directory. Does that fix it?

  2. Ned Batchelder repo owner

    Yes, make one if you don't have one. Also, I wonder why you are using the API, why not just run coverage commands?

  3. Abel Asefa reporter

    I have created the file (even though it is just an empty file), and now the COVERAGE_PROCESS_START refers to it.

    I have also tested it with the command but it is still the same, it doesn't show the coverage of the sub process

    coverage run --parallel index_Copy.py
    

    Capture.PNG

    import subprocess
    from_sub_process = subprocess.check_output(['python', 'test3.py'])
    from_sub_process = str(from_sub_process)
    def test_a():
        return "a"
    def test_b(character):
        global from_sub_process
        from_sub_process += character
    test_b(test_a())
    
  4. Ned Batchelder repo owner

    Put something in the file: [run] parallel=True for example. I'm not sure what happens with a completely empty rc file.

  5. Abel Asefa reporter

    Okay Now, it is working, the problem was it wasn't getting the sitecustomize.py file since I had it placed inside scripts/site-packages. It works when I moved it to Lib/site-packages.

    Thanks Ned for the support and the awesome tool.

  6. Log in to comment