Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I send results of a test as a parameter to my python script?

Tags:

python

cypress

I created a scheduled task and my cypress script is being run once an hour. But after that I want to execute a python script and pass the result data there.

Run the script and get the "results" as failed or success.

$ cypress run --spec "cypress/integration/myproject/myscript.js"

And pass the "results" data to a python script.

$ python test.py results

How can I do this?

like image 815
Firat Yılmaz Avatar asked Sep 07 '25 23:09

Firat Yılmaz


1 Answers

There is a subprocess module which is able to run external commands, here is the example:

import subprocess

def get_test_output():
    filepath = './cypress/integration/myproject/myscript.js'

    res = subprocess.run(
        ['echo', filepath],
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT,
    )
    # In your case it will be:
    # res = subprocess.run(
    #     ['cypress', 'run', '--spec', filepath],
    #     stdout=subprocess.PIPE,
    #     stderr=subprocess.STDOUT,
    # )

    return res.stdout.decode()


if __name__ == '__main__':
    test_res = get_test_output()

    print(test_res)
    # => ./cypress/integration/myproject/myscript.js

You could run cypress in the begining of test.py and pass results further to needed functions

like image 134
Alex Kosh Avatar answered Sep 09 '25 12:09

Alex Kosh