Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
630 views
in Technique[技术] by (71.8m points)

bdd - Python Paver Script - return exit code 1 after command runs if a subprocess/thread exit code is 1

I am trying to run a paver script and upon failure in the subprocesses, the main command returns with exit code 0.

Subprocess output: paver.tasks.BuildFailure: Subprocess return code: 1

Command output: ==> Script finished with exit code: 0

I can't figure out how to get the entire command to finish running and return exit code 1 if any of the subprocesses threw an error.

Sample code:

from paver.easy import *
from paver.setuputils import setup
import threading, os, platform

setup(
    name = "behave-browserstack",
    version = "0.1.0",
    author = "BrowserStack",
    author_email = "support@browserstack.com",
    description = ("Behave Integration with BrowserStack"),
    license = "MIT",
    keywords = "example selenium browserstack",
    url = "https://github.com/browserstack/lettuce-browserstack",
    packages=['features']
)

def run_behave_test(config, feature, task_id=0):
    if platform.system() == 'Windows':
        sh('SET CONFIG_FILE=config/%s.json & SET TASK_ID=%s & behave features/%s.feature' % (config, task_id, feature))
    else:
        sh('export CONFIG_FILE=config/%s.json && export TASK_ID=%s && behave features/%s.feature' % (config, task_id, feature))

@task
@consume_nargs(1)
def run(args):
    """Run single, local and parallel test using different config."""
    if args[0] in ('single', 'local'):
        run_behave_test(args[0], args[0])
    else:
        jobs = []
        for i in range(4):
            p = threading.Thread(target=run_behave_test,args=(args[0], "single",i))
            jobs.append(p)
            p.start()

        for th in jobs:
            th.join()

@task
def test():
    """Run all tests"""
    sh("paver run single")
    sh("paver run local")
    sh("paver run parallel")
question from:https://stackoverflow.com/questions/65626427/python-paver-script-return-exit-code-1-after-command-runs-if-a-subprocess-thre

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...