Skip to content

coverage report failed to generate due to the IndexError: list index out of range #1620

Closed as not planned
@nlou9

Description

@nlou9

Describe the bug
Currently we are using bazel coverage to get the coverage report with Bazel. We have all the tests passed but the coverage report will show this error. (Bazel coverage is using coveragepy to generate coverage report)

Converting coveragepy database to lcov: /private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/sandbox/darwin-sandbox/6/execroot/__main__/bazel-out/darwin-fastbuild/testlogs/_coverage/common_tools_test/test/pylcov.dat
Wrote LCOV report to /private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/sandbox/darwin-sandbox/6/execroot/__main__/bazel-out/darwin-fastbuild/testlogs/_coverage/common_tools_test/test/pylcov.dat
Traceback (most recent call last):
  File "/private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/sandbox/darwin-sandbox/6/execroot/__main__/bazel-out/darwin-fastbuild/bin/common_tools_test.runfiles/python311_x86_64-apple-darwin_coverage/coverage/__main__.py", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/sandbox/darwin-sandbox/6/execroot/__main__/bazel-out/darwin-fastbuild/bin/common_tools_test.runfiles/python311_x86_64-apple-darwin_coverage/coverage/cmdline.py", line 944, in main
    status = CoverageScript().command_line(argv)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/sandbox/darwin-sandbox/6/execroot/__main__/bazel-out/darwin-fastbuild/bin/common_tools_test.runfiles/python311_x86_64-apple-darwin_coverage/coverage/cmdline.py", line 720, in command_line
    total = self.coverage.lcov_report(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/sandbox/darwin-sandbox/6/execroot/__main__/bazel-out/darwin-fastbuild/bin/common_tools_test.runfiles/python311_x86_64-apple-darwin_coverage/coverage/control.py", line 1102, in lcov_report
    return render_report(self.config.lcov_output, LcovReporter(self), morfs, self._message)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/sandbox/darwin-sandbox/6/execroot/__main__/bazel-out/darwin-fastbuild/bin/common_tools_test.runfiles/python311_x86_64-apple-darwin_coverage/coverage/report.py", line 35, in render_report
    return reporter.report(morfs, outfile=outfile)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/sandbox/darwin-sandbox/6/execroot/__main__/bazel-out/darwin-fastbuild/bin/common_tools_test.runfiles/python311_x86_64-apple-darwin_coverage/coverage/lcovreport.py", line 34, in report
    self.get_lcov(fr, analysis, outfile)
  File "/private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/sandbox/darwin-sandbox/6/execroot/__main__/bazel-out/darwin-fastbuild/bin/common_tools_test.runfiles/python311_x86_64-apple-darwin_coverage/coverage/lcovreport.py", line 57, in get_lcov
    line = source_lines[covered-1].encode("utf-8")
           ~~~~~~~~~~~~^^^^^^^^^^^
IndexError: list index out of range

To Reproduce
How can we reproduce the problem? Please be specific. Don't link to a failing CI job. Answer the questions below:

  1. What version of Python are you using?
    python 3.9.16
  2. What version of coverage.py shows the problem? The output of coverage debug sys is helpful.
-- sys -------------------------------------------------------
               coverage_version: 7.2.5
                coverage_module: /Users/nlou/.pyenv/versions/3.9.16/lib/python3.9/site-packages/coverage/__init__.py
                         tracer: -none-
                        CTracer: available
           plugins.file_tracers: -none-
            plugins.configurers: -none-
      plugins.context_switchers: -none-
              configs_attempted: .coveragerc
                   configs_read: /Users/nlou/workspace/common-tools/.coveragerc
                    config_file: /Users/nlou/workspace/common-tools/.coveragerc
                config_contents: b'[run]\nomit =\n    .git/*\n    .tox/*\n    docs/*\n    setup.py\n    test/*\n    tests/*\n    bazel-*\n'
                      data_file: -none-
                         python: 3.9.16 (main, Apr 17 2023, 23:50:29) [Clang 14.0.0 (clang-1400.0.29.202)]
                       platform: macOS-12.6.5-x86_64-i386-64bit
                 implementation: CPython
                     executable: /Users/nlou/.pyenv/versions/3.9.16/bin/python
                   def_encoding: utf-8
                    fs_encoding: utf-8
                            pid: 47058
                            cwd: /Users/nlou/workspace/common-tools
                           path: /private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/external/python311_x86_64-apple-darwin_coverage/coverage
                                 /Users/nlou/.pyenv/versions/3.9.16/lib/python39.zip
                                 /Users/nlou/.pyenv/versions/3.9.16/lib/python3.9
                                 /Users/nlou/.pyenv/versions/3.9.16/lib/python3.9/lib-dynload
                                 /Users/nlou/.local/lib/python3.9/site-packages
                                 /Users/nlou/.pyenv/versions/3.9.16/lib/python3.9/site-packages
                    environment: HOME = /Users/nlou
                                 PYENV_DIR = /Users/nlou/workspace/common-tools
                                 PYENV_HOOK_PATH = /Users/nlou/.pyenv/pyenv.d:/usr/local/Cellar/pyenv/2.3.17/pyenv.d:/usr/local/etc/pyenv.d:/etc/pyenv.d:/usr/lib/pyenv/hooks
                                 PYENV_ROOT = /Users/nlou/.pyenv
                                 PYENV_SHELL = zsh
                                 PYENV_VERSION = 3.9.16
                   command_line: /private/var/tmp/_bazel_nlou/b43af9baf9d056244183c6c3d6dd8487/sandbox/darwin-sandbox/6/execroot/__main__/bazel-out/darwin-fastbuild/bin/common_tools_test.runfiles/python311_x86_64-apple-darwin_coverage/coverage/__main__.py debug sys
         sqlite3_sqlite_version: 3.37.0
             sqlite3_temp_store: 0
        sqlite3_compile_options: ATOMIC_INTRINSICS=1, BUG_COMPATIBLE_20160819, COMPILER=clang-13.1.6,
                                 DEFAULT_AUTOVACUUM, DEFAULT_CACHE_SIZE=2000, DEFAULT_CKPTFULLFSYNC,
                                 DEFAULT_FILE_FORMAT=4, DEFAULT_JOURNAL_SIZE_LIMIT=32768,
                                 DEFAULT_LOOKASIDE=1200,102, DEFAULT_MEMSTATUS=0, DEFAULT_MMAP_SIZE=0,
                                 DEFAULT_PAGE_SIZE=4096, DEFAULT_PCACHE_INITSZ=20,
                                 DEFAULT_RECURSIVE_TRIGGERS, DEFAULT_SECTOR_SIZE=4096,
                                 DEFAULT_SYNCHRONOUS=2, DEFAULT_WAL_AUTOCHECKPOINT=1000,
                                 DEFAULT_WAL_SYNCHRONOUS=1, DEFAULT_WORKER_THREADS=0, ENABLE_API_ARMOR,
                                 ENABLE_BYTECODE_VTAB, ENABLE_COLUMN_METADATA, ENABLE_DBSTAT_VTAB,
                                 ENABLE_FTS3, ENABLE_FTS3_PARENTHESIS, ENABLE_FTS3_TOKENIZER, ENABLE_FTS4,
                                 ENABLE_FTS5, ENABLE_JSON1, ENABLE_LOCKING_STYLE=1, ENABLE_NORMALIZE,
                                 ENABLE_PREUPDATE_HOOK, ENABLE_RTREE, ENABLE_SESSION, ENABLE_SNAPSHOT,
                                 ENABLE_SQLLOG, ENABLE_STMT_SCANSTATUS, ENABLE_UNKNOWN_SQL_FUNCTION,
                                 ENABLE_UPDATE_DELETE_LIMIT, HAS_CODEC_RESTRICTED, HAVE_ISNAN,
                                 MALLOC_SOFT_LIMIT=1024, MAX_ATTACHED=10, MAX_COLUMN=2000,
                                 MAX_COMPOUND_SELECT=500, MAX_DEFAULT_PAGE_SIZE=8192, MAX_EXPR_DEPTH=1000,
                                 MAX_FUNCTION_ARG=127, MAX_LENGTH=2147483645, MAX_LIKE_PATTERN_LENGTH=50000,
                                 MAX_MMAP_SIZE=1073741824, MAX_PAGE_COUNT=1073741823, MAX_PAGE_SIZE=65536,
                                 MAX_SQL_LENGTH=1000000000, MAX_TRIGGER_DEPTH=1000,
                                 MAX_VARIABLE_NUMBER=500000, MAX_VDBE_OP=250000000, MAX_WORKER_THREADS=8,
                                 MUTEX_UNFAIR, OMIT_AUTORESET, OMIT_LOAD_EXTENSION, STMTJRNL_SPILL=131072,
                                 SYSTEM_MALLOC, TEMP_STORE=1, THREADSAFE=2, USE_URI
  1. What versions of what packages do you have installed? The output of pip freeze is helpful.
#
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
#    bazel run //:requirements.update
#
alabaster==0.7.13 \
    # via sphinx
babel==2.11.0 \
    # via sphinx
certifi==2022.12.7 \
    # via requests
charset-normalizer==3.0.1 \

    # via requests
click==8.1.3 \
    # via -r ./requirements.in
docutils==0.19 \

    # via sphinx
execnet==1.9.0 \
    # via pytest-xdist
flake8==6.0.0 \
    # via -r ./requirements.in
idna==3.4 \
    # via requests
imagesize==1.4.1 \
    # via sphinx
iniconfig==2.0.0 \
    # via pytest
jinja2==3.1.2 \
    # via
    #   -r ./requirements.in
    #   sphinx
markupsafe==2.1.2 \
    # via jinja2
mccabe==0.7.0 \
    # via flake8
mock==5.0.1 \
    # via -r ./requirements.in
packaging==23.0 \
    # via
    #   pytest
    #   sphinx
pluggy==1.0.0 \
    # via pytest
pycodestyle==2.10.0 \
    # via flake8
pyflakes==3.0.1 \
    # via flake8
pygments==2.14.0 \
    # via sphinx
pytest==7.3.1 \
    # via
    #   -r ./requirements.in
    #   pytest-xdist
pytest-xdist==3.1.0 \
    # via -r ./requirements.in
pytz==2022.7.1 \
    # via babel
requests==2.28.2 \
    # via
    #   slackclient
    #   sphinx
six==1.16.0 \
    # via
    #   slackclient
    #   websocket-client
slackclient==1.3.1 \
    # via -r ./requirements.in
snowballstemmer==2.2.0 \
    # via sphinx
sphinx==6.1.3 \
    # via -r ./requirements.in
sphinxcontrib-applehelp==1.0.1 \
    # via
    #   -r ./requirements.in
    #   sphinx
sphinxcontrib-devhelp==1.0.2 \
    # via sphinx
sphinxcontrib-htmlhelp==2.0.0 \
    # via sphinx
sphinxcontrib-jsmath==1.0.1 \
    # via sphinx
sphinxcontrib-qthelp==1.0.3 \
    # via sphinx
sphinxcontrib-serializinghtml==1.1.5 \
    # via sphinx
urllib3==1.26.14 \
    # via requests
websocket-client==0.54.0 \
    # via slackclient

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingduplicateThis issue or pull request already exists

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions