Home > Net >  coverage.misc.NoSource: No source for code: '/usr/src/server/rep-1>'
coverage.misc.NoSource: No source for code: '/usr/src/server/rep-1>'

Time:12-29

I am using the coverage package for quite a while now and it functioned well until yesterday it just fails at the level of generating a report I believe. There were no changes on how the functionality which is way more bizarre.

I have the below coveragerc file:

[run]
source = .
branch = True
concurrency = multiprocessing
omit =
    manage.py
    config/asgi.py
    config/wsgi.py
    config/settings.py
    */migrations/*
    *test*

[report]
show_missing = True
skip_covered = True

and Django manage.py file is as the following:

import os
import sys


COVERAGE_ACCCEPTANCE = 85


def main():
    argv = sys.argv
    try:
        command = argv[1]
    except IndexError:
        command = "help"
    default_settings = "config.settings"
    running_tests = (command == "test")
    if running_tests:
        default_settings = "config.settings_test"
        from coverage import Coverage
        cov = Coverage()
        cov.erase()
        cov.start()
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", default_settings)
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?",
        ) from exc
    execute_from_command_line(argv)
    if running_tests:
        cov.stop()
        cov.save()
        cov.combine()
        if round(cov.report()) < COVERAGE_ACCCEPTANCE:
            sys.exit(1)
        cov.erase()


if __name__ == "__main__":
    main()

After the tests are run successfully, the coverage raises the below error:

Ran 317 tests in 96.790s
OK
Destroying test database for alias 'default'...
Traceback (most recent call last):
File "./serverX/manage.py", line 44, in <module>
    main()
File "./serverX/manage.py", line 38, in main
    if round(cov.report()) < COVERAGE_ACCCEPTANCE:
File "/usr/local/lib/python3.8/site-packages/coverage/control.py", line 913, in report
    return reporter.report(morfs, outfile=file)
File "/usr/local/lib/python3.8/site-packages/coverage/summary.py", line 45, in report
    for fr, analysis in get_analysis_to_report(self.coverage, morfs):
File "/usr/local/lib/python3.8/site-packages/coverage/report.py", line 70, in get_analysis_to_report
    analysis = coverage._analyze(fr)
File "/usr/local/lib/python3.8/site-packages/coverage/control.py", line 808, in _analyze
    return Analysis(data, it, self._file_mapper)
File "/usr/local/lib/python3.8/site-packages/coverage/results.py", line 20, in __init__
    self.statements = self.file_reporter.lines()
File "/usr/local/lib/python3.8/site-packages/coverage/python.py", line 191, in lines
    return self.parser.statements
File "/usr/local/lib/python3.8/site-packages/coverage/python.py", line 182, in parser
    self._parser = PythonParser(
File "/usr/local/lib/python3.8/site-packages/coverage/parser.py", line 44, in __init__
    self.text = get_python_source(self.filename)
File "/usr/local/lib/python3.8/site-packages/coverage/python.py", line 61, in get_python_source
    raise NoSource(exc_msg)
coverage.misc.NoSource: No source for code: '/usr/src/server/rep-1>'.
Aborting report output, consider using -i.
1
Cleaning up project directory and file based variables 00:01
ERROR: Job failed: exit code 1

I think perhaps the file it says is not found (/usr/src/server/rep-1) is the generated report since I don't have any such files on my repo. I really appreciate any insights as this has been a bit odd and I could not find anything on the docs or the package issues on GitHub/ stackoverflow that resembles this instance.

I am running on Django 3.1 with coverage 5.5 on GitLab pipelines.

CodePudding user response:

I found the root cause was the attrs==21.3.0 library was published today. If I use version 21.2.0 then coverage report does not fail because of absent representation files.

See https://github.com/pytest-dev/pytest/discussions/9459

  • Related