IndexError: list index out of range on coverage lcov · Issue #1553 · nedbat/coveragepy (original) (raw)

Describe the bug
I'm running coverage lcov and getting the following error: IndexError: list index out of range
This error mostly match this old report: #1362

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?
    3.10.8
  2. What version of coverage.py shows the problem? The output of coverage debug sys is helpful.
               coverage_version: 7.1.0
                coverage_module: /opt/homebrew/lib/python3.10/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/md/api/.coveragerc
                    config_file: /Users/md/api/.coveragerc
                config_contents: b'[run]\nomit = ./venv/*,*test/*,*apps.py,*manage.py,*__init__.py,*migrations*,*admin.py,*urls.py\nrelative_files = True\n\n[report]\nomit = ./venv/*,*test/*,*apps.py,*manage.py,*__init__.py,*migrations*,*admin.py,*urls.py\n'
                      data_file: -none-
                         python: 3.10.8 (main, Oct 21 2022, 22:22:30) [Clang 14.0.0 (clang-1400.0.29.202)]
                       platform: macOS-13.1-arm64-arm-64bit
                 implementation: CPython
                     executable: /opt/homebrew/opt/python@3.10/bin/python3.10
                   def_encoding: utf-8
                    fs_encoding: utf-8
                            pid: 46910
                            cwd: /Users/md/api
                           path: /opt/homebrew/bin
                                 /opt/homebrew/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python310.zip
                                 /opt/homebrew/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10
                                 /opt/homebrew/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/lib-dynload
                                 /Users/md/Library/Python/3.10/lib/python/site-packages
                                 /opt/homebrew/lib/python3.10/site-packages
                                 __editable__.rapydo-3.0.finder.__path_hook__
                                 /Users/md/infra/cli
                    environment: HOME = /Users/md
                                 RAPYDO = /Users/md/rapydo/components
                   command_line: /opt/homebrew/bin/coverage debug sys
         sqlite3_sqlite_version: 3.39.4
             sqlite3_temp_store: 0
        sqlite3_compile_options: ATOMIC_INTRINSICS=1, COMPILER=clang-14.0.0, DEFAULT_AUTOVACUUM,
                                 DEFAULT_CACHE_SIZE=-2000, DEFAULT_FILE_FORMAT=4,
                                 DEFAULT_JOURNAL_SIZE_LIMIT=-1, 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=2,
                                 DEFAULT_WORKER_THREADS=0, ENABLE_COLUMN_METADATA, ENABLE_FTS3,
                                 ENABLE_FTS3_PARENTHESIS, ENABLE_FTS4, ENABLE_FTS5, ENABLE_GEOPOLY,
                                 ENABLE_MATH_FUNCTIONS, ENABLE_PREUPDATE_HOOK, ENABLE_RTREE, ENABLE_SESSION,
                                 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=1000000000, MAX_LIKE_PATTERN_LENGTH=50000,
                                 MAX_MMAP_SIZE=0x7fff0000, MAX_PAGE_COUNT=1073741823, MAX_PAGE_SIZE=65536,
                                 MAX_SQL_LENGTH=1000000000, MAX_TRIGGER_DEPTH=1000,
                                 MAX_VARIABLE_NUMBER=250000, MAX_VDBE_OP=250000000, MAX_WORKER_THREADS=8,
                                 MUTEX_PTHREADS, SYSTEM_MALLOC, TEMP_STORE=1, THREADSAFE=1
  1. What versions of what packages do you have installed? The output of pip freeze is helpful.
  2. What code shows the problem? Give us a specific commit of a specific repo that we can check out. If you've already worked around the problem, please provide a commit before that fix.
  3. What commands did you run?
pytest --cov-report=term-missing --cov=internal/ --cov=a/internal/ --cov=b/internal/ --cov=c/internal/ --cov=d/internal/ --cov=e/internal/  --cov=f/internal/ --cov=g/internal/
coverage lcov

Expected behavior
I expect it to write to the lcov file without error

Additional context
Add any other context about the problem here.

I was playing with the .coverage -> coverage.lcov conversion and I noticed a different behaviour between coverage 6.5.0 and any 7.x version

version 7 fails with error:

$ coverage lcov

Wrote LCOV report to coverage.lcov
Traceback (most recent call last):
  File "/opt/homebrew/bin/coverage", line 8, in <module>
    sys.exit(main())
  File "/opt/homebrew/lib/python3.10/site-packages/coverage/cmdline.py", line 972, in main
    status = CoverageScript().command_line(argv)
  File "/opt/homebrew/lib/python3.10/site-packages/coverage/cmdline.py", line 744, in command_line
    total = self.coverage.lcov_report(
  File "/opt/homebrew/lib/python3.10/site-packages/coverage/control.py", line 1233, in lcov_report
    return render_report(self.config.lcov_output, LcovReporter(self), morfs, self._message)
  File "/opt/homebrew/lib/python3.10/site-packages/coverage/report.py", line 59, in render_report
    return reporter.report(morfs, outfile=outfile)
  File "/opt/homebrew/lib/python3.10/site-packages/coverage/lcovreport.py", line 45, in report
    self.get_lcov(fr, analysis, outfile)
  File "/opt/homebrew/lib/python3.10/site-packages/coverage/lcovreport.py", line 72, in get_lcov
    line = source_lines[covered-1].encode("utf-8")
IndexError: list index out of range

while coverage 6 is fine:

$ coverage lcov

Wrote LCOV report to coverage.lcov

But also the report is different,

coverage 6 only reports few files (only from the first --cov)

$ coverage report
Name                                 Stmts   Miss  Cover
--------------------------------------------------------
internal/constants.py                    7      0   100%
internal/forms.py                      231      5    98%
internal/hooks.py                       18      0   100%
internal/mixins.py                      62      1    98%
internal/permissions.py                  5      0   100%
internal/read_only_settings.py           2      2     0%
internal/rests.py                       18      0   100%
internal/serializers.py                448    161    64%
internal/templatetags/utilities.py      32      1    97%
internal/views.py                      831    168    80%
internal/widgets.py                     27      2    93%
--------------------------------------------------------
TOTAL                                 1681    340    80%

On the opposite coverage 7 reports the whole list of files from all the --cov

coverage report                                                                                                        
Name                                                            Stmts   Miss  Cover
-----------------------------------------------------------------------------------
a/internal/test/test_dashboard_detail_view.py        30      0   100%
b/internal/test/test_dashboard_views.py               33      0   100%
b/internal/test/test_platform_management.py           21      0   100%
b/internal/test/test_dashboard_detail_views.py           109      1    99%
b/internal/test/test_dashboard_serializers.py             68      1    99%
b/internal/test/test_dashboard_views.py                   59      0   100%
internal/constants.py                                               7      0   100%
internal/forms.py                                                 231      5    98%
internal/hooks.py                                                  18      0   100%
internal/mixins.py                                                 62      1    98%
internal/permissions.py                                             5      0   100%
internal/read_only_settings.py                                      2      2     0%
.... redacted ... very long list

Probably the fact that coverage 6 is successful is because it is only consider a few files and this other issue was about coverage version 6.3.2, so I don't think it is a regression with coverage 7