How can I run a script as part of a Travis CI build?

允我心安 提交于 2020-02-03 04:40:12

问题


As part of a Python package I have a script myscript.py at the root of my project and

setup(scripts=['myscript.py'], ...) 

in my setup.py.

Is there an entry I can provide to my .travis.yml that will run myscript.py (e.g. after my tests)?

I've tried

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.

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).

How can I run a package script as part of a Travis CI build?


回答1:


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

(Prepending python in the last line.)

Aside: travis should have pytest preinstalled.


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


来源:https://stackoverflow.com/questions/33703325/how-can-i-run-a-script-as-part-of-a-travis-ci-build

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!