orome
orome

Reputation: 48616

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

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?

Upvotes: 7

Views: 4900

Answers (1)

Andy Hayden
Andy Hayden

Reputation: 375925

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

Upvotes: 9

Related Questions