archived-codacy / python-codacy-coverage

DEPRECATED Python coverage reporter for Codacy
BSD 3-Clause "New" or "Revised" License
45 stars 38 forks source link

TypeError: cannot concatenate 'str' and 'list' objects #28

Closed anentropic closed 7 years ago

anentropic commented 7 years ago
$ python-codacy-coverage -r target/coverage.xml
Traceback (most recent call last):
  File "/VENV/bin/python-codacy-coverage", line 11, in <module>
    sys.exit(main())
  File "/VENV/lib/python2.7/site-packages/codacy/__init__.py", line 6, in main
    return reporter.run()
  File "/VENV/lib/python2.7/site-packages/codacy/reporter.py", line 189, in run
    logging.error("Coverage report " + args.report + " not found.")
TypeError: cannot concatenate 'str' and 'list' objects
anentropic commented 7 years ago

the logic here is wrong

def run():
    parser = argparse.ArgumentParser(description='Codacy coverage reporter for Python.')
    parser.add_argument("-r", "--report", help="coverage report file",
                        default=[DEFAULT_REPORT_FILE], type=str,
                        action='append')
    parser.add_argument("-c", "--commit", type=str, help="git commit hash")
    parser.add_argument("-d", "--directory", type=str, help="git top level directory")
    parser.add_argument("-v", "--verbose", help="show debug information", action="store_true")

    args = parser.parse_args()

    if args.verbose:
        logging.Logger.setLevel(logging.getLogger(), logging.DEBUG)

    if not CODACY_PROJECT_TOKEN:
        logging.error("environment variable CODACY_PROJECT_TOKEN is not defined.")
        exit(1)

    if not args.commit:
        args.commit = get_git_revision_hash()

    # Explictly check ALL files before parsing any
    for rfile in args.report:
        if not os.path.isfile(rfile):
            logging.error("Coverage report " + args.report + " not found.")
            exit(1)

Firstly, the logging should be:

logging.error("Coverage report " + rfile + " not found.")

But more importantly, it is failing because my specified path has been appended to [DEFAULT_REPORT_FILE] and the default path doesn't exist. Basically default path should only be added if no user-specified paths are supplied.

I will make a PR

machadoit commented 7 years ago

Fixed by https://github.com/codacy/python-codacy-coverage/releases/tag/1.3.2