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

2024/10/4 21:27:39

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: pythonpython:- "2.7"install:- pip install -r requirements.txt- pip install pytestscript:- 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?

Answer

As mentioned in the comments (you need to call python):

language: pythonpython:- "2.7"install:- pip install -r requirements.txt- pip install pytestscript:- 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: pythonpython:- "2.7"install:- pip install -r requirements.txt- pip install pytestscript:- py.test -v --color=yes --exitfirst --showlocals --durations=5after_success:- python myscript.py some args
https://en.xdnf.cn/q/70558.html

Related Q&A

Writing nested schema to BigQuery from Dataflow (Python)

I have a Dataflow job to write to BigQuery. It works well for non-nested schema, however fails for the nested schema.Here is my Dataflow pipeline:pipeline_options = PipelineOptions()p = beam.Pipeline(o…

Python decorators on class members fail when decorator mechanism is a class

When creating decorators for use on class methods, Im having trouble when the decorator mechanism is a class rather than a function/closure. When the class form is used, my decorator doesnt get treated…

Why does comparison of a numpy array with a list consume so much memory?

This bit stung me recently. I solved it by removing all comparisons of numpy arrays with lists from the code. But why does the garbage collector miss to collect it?Run this and watch it eat your memor…

StringIO portability between python2 and python3 when capturing stdout

I have written a python package which I have managed to make fully compatible with both python 2.7 and python 3.4, with one exception that is stumping me so far. The package includes a command line scr…

How to redirect data to a getpass like password input?

Im wring a python script for running some command. Some of those commands require user to input password, I did try to input data in their stdin, but it doesnt work, here is two simple python program…

How to grab one random item from a database in Django/postgreSQL?

So i got the database.objects.all() and database.objects.get(name) but how would i got about getting one random item from the database. Im having trouble trying to figure out how to get it ot select on…

Pyspark Dataframe pivot and groupby count

I am working on a pyspark dataframe which looks like belowid category1 A1 A1 B2 B2 A3 B3 B3 BI want to unstack the category column and count their occurrences. So, the result I want is shown belowid A …

Create an excel file from BytesIO using python

I am using pandas library to store excel into bytesIO memory. Later, I am storing this bytesIO object into SQL Server as below-df = pandas.DataFrame(data1, columns=[col1, col2, col3])output = BytesIO()…

python send csv data to spark streaming

I would like to try and load a csv data in python and stream each row spark via SPark Streaming.Im pretty new to network stuff. Im not exactly if Im supposed to create a server python script that once …

Python string representation of binary data

Im trying to understand the way Python displays strings representing binary data.Heres an example using os.urandomIn [1]: random_bytes = os.urandom(4)In [2]: random_bytes Out[2]: \xfd\xa9\xbe\x87In [3]…