如何将脚本作为 Travis CI 构建的一部分运行? [英] How can I run a script as part of a Travis CI build?
问题描述
作为 Python 包的一部分,我在项目的根目录中有一个脚本 myscript.py
和
As part of a Python package I have a script myscript.py
at the root of my project and
setup(scripts=['myscript.py'], ...)
在我的 setup.py
中.
是否有我可以提供给我的 .travis.yml
的条目来运行 myscript.py
(例如在我的测试之后)?
Is there an entry I can provide to my .travis.yml
that will run myscript.py
(e.g. after my tests)?
我试过了
language: python
python:
- "2.7"
install:
- pip install -r requirements.txt
- pip install pytest
script:
- py.test -v --color=yes --exitfirst --showlocals --durations=5
- myscript.py some args
但收到找不到命令"错误.
but get a "command not found" error.
我不需要(或真的希望)脚本成为测试套件的一部分,我只想在 Travis 日志中看到它的输出(当然,如果构建出错,则构建失败).
I don't need (or really want) the script to be part of the test suite, I just want to see it's output in the Travis log (and, of corse, fail the build if it errors).
如何将包脚本作为 Travis CI 构建的一部分运行?
How can I run a package script as part of a Travis CI build?
推荐答案
如评论中所述(需要调用python):
As mentioned in the comments (you need to call python):
language: python
python:
- "2.7"
install:
- pip install -r requirements.txt
- pip install pytest
script:
- py.test -v --color=yes --exitfirst --showlocals --durations=5
- python myscript.py some args
(在最后一行添加 python.)
(Prepending python in the last line.)
旁白:travis 应该预装了 pytest.
Aside: travis should have pytest preinstalled.
还有一个 after_success
块在这些情况下很有用(仅在测试通过时运行脚本,并且不影响构建的成功)-通常用于发布覆盖率统计数据.
There's also an after_success
block which can be useful in these cases (for running a script only if the tests pass, and not affecting the success of the builds) - often this is used for posting coverage stats.
language: python
python:
- "2.7"
install:
- pip install -r requirements.txt
- pip install pytest
script:
- py.test -v --color=yes --exitfirst --showlocals --durations=5
after_success:
- python myscript.py some args
这篇关于如何将脚本作为 Travis CI 构建的一部分运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!