【问题标题】:How do I integrate travis ci with codeclimate test coverage in Python?如何将 travis ci 与 Python 中的 codeclimate 测试覆盖率集成?
【发布时间】:2016-06-26 23:10:14
【问题描述】:

我正在尝试让我的 Travis CI 将测试覆盖率数据发送到 Code Climate 服务,但是关于 Code Climate 和 Travis CI 的文档没有详细描述如何使用 Python 执行此操作。根据 Code Climate 和 Travis 文档,它仍然支持它的功能。我试图在没有运气的情况下找到任何可行的示例,并且无法自行完成。

代码气候文档: Setting Up Test Coverage, Readme: codeclimate-test-reporter

特拉维斯 CI 文档: Using Code Climate with Travis CI

我已经在 Travis CI 中设置了 CODECLIMATE_REPO_TOKEN,如本答案所述: https://stackoverflow.com/a/31281481/1754089

我的 .travis.yml 文件:

language: python
python:
  - 2.7
install:
  - pip install -r requirements.txt
  - pip install coverage
  - pip install codeclimate-test-reporter
#commands to run tests:
script:
  - python mytests.py
  - coverage run mytests.py
after_success:
  - codeclimate-test-reporter

由于在 Travis 中执行 after_success 行,它在日志视图中给了我这个:

/home/travis/build.sh: line 45: codeclimate-test_reporter: command not found

【问题讨论】:

  • 根据您的错误信息,您的脚本中有错字。注意codeclimate-test_reporter 中的下划线。

标签: python python-2.7 continuous-integration travis-ci code-climate


【解决方案1】:

确实,在您看来,这只是彼得在评论中提到的一种类型的问题。你的 after_success 应该有 codeclimate-test-reporter - 看起来你有它,但 travis 正在报告其他内容。

现在我为什么要开放赏金,以及为什么实际上只是我不了解 codeclimate_test_reporter 的工作原理。我想从 py.test 报告我的报道。 codeclimate_test_reporter 在 GitHub 上有一个漂亮的自述文件,显示 how to create a coverage report。但是,从他们的示例来看,提供 codeclimate-test-reporter 作为 --cov 的参数似乎会自动向 codeclimate 发送报告。事实并非如此

使用py.test,你想做的是:

script:
- py.test --cov=YourModuleYouWantToCover test_folder
- codeclimate-test-reporter --file .coverage

神奇的发生了,我第一次有关于 codeclimate 的覆盖率报告!

我向 codeclimate-test-reporter 提交了一个拉取请求以更新他们的自述文件,并且它已被合并,因此希望对未来的人们减少混淆!

【讨论】:

  • 感谢您的时间和努力!
【解决方案2】:

codeclimate python-test-reporter 已被弃用。使用 travis-ci 处理 python 测试报告的更新方法可以在https://github.com/codeclimate/test-reporter/blob/master/examples/python_examples.md找到。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-18
    • 1970-01-01
    • 2013-10-14
    • 2015-04-05
    相关资源
    最近更新 更多