Pytest失败,退出代码2与Jenkins

ca1c2owp  于 2023-08-03  发布在  Jenkins
关注(0)|答案(1)|浏览(129)

我用下面的命令运行了pytest...
第一个月
我得到了以下错误:
错误:脚本返回退出代码2
以下是我的JenkinsFile:

//#!/bin/bash
//#!groovy

def withConda(Closure body) {
    //CONDA INSTALLATION-------------------------------------
    env.CONDA_ZIP               = 'miniconda3.sh'
    env.CERTS_ZIP               = 'certs.zip'
    env.CONDA_PATH              = "${WORKSPACE}/bin/anaconda3"
    env.CONDA_BIN_DIR           = "${env.CONDA_PATH}/bin"

    //GENERIC DIRECTORIES------------------------------------
    env.DOWNLOADS               = "${WORKSPACE}/downloads"
    env.WORKSPACE_BIN           = "${WORKSPACE}/bin"

    if ( fileExists("${env.CONDA_PATH}/tls-ca-bundle.pem") ) {
        echo "=====================>> CONDA ALREADY INSTALLED! <<====================="
    } else {
        echo "=====================>> INSTALLING CONDA! <<====================="
        stage('Installing Miniconda3') {
            dir("${env.DOWNLOADS}") {
                sh "curl -k -o ${env.CONDA_ZIP} https://nexus.com/nexus/content/repositories/third-party-applications/continuum/miniconda3/4.4.10/Miniconda3-latest-Linux-x86_64.sh  --insecure"
                sh "chmod +x ${env.CONDA_ZIP}"
                sh "curl -k -o ${env.CERTS_ZIP} 'https://nexus.com/nexus/service/local/repositories/ib-cto-releases/content/com/cacerts/java-cacerts/3.1.0/java-cacerts-3.1.0.zip' --insecure"

                dir("${env.CONDA_PATH}") {
                    sh "unzip  -d . -u ${env.DOWNLOADS}/${env.CERTS_ZIP}"
                    //sh 'ls -lart'
                    sh "bash ${env.DOWNLOADS}/${env.CONDA_ZIP} -b -f -p ."

                }
            }
        }
    }

    stage('Setting Up Conda Configuration') {
        dir ("${env.CONDA_PATH}") {
            sh "mv ${env.JENKINS_PIPELINES_PATH}/.condarc ./.condarc"
            sh "sed -i 's+TLS_PEM_BUNDLE_PATH+${env.CONDA_PATH}/tls-ca-bundle.pem+'  .condarc"
        }
        withEnv(["PATH+CONDA_BIN_DIR=${env.CONDA_BIN_DIR}"])  {
            sh 'python -m conda update conda -y'
            //sh 'conda update conda -y'
            //sh 'conda update --all -y'
            sh 'conda env list'
            //sh 'conda remove --name dev --all -y'

            withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: "d398a781-1860-4c2b-96b6-dbd5442f9a82", usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {
                body()
            }
        }
    }
}

def withSpark(Closure body) {
    //JAVA INSTALLATION-------------------------------------
    //env.JAVA_ZIP = 'java.sh'
    stage('Setting Up Spark Configuration')
        dir("${env.DOWNLOADS}") {
            echo "=====================>> INSTALLING JAVA! <<====================="
            // cannot find java on Nexus
            sh "curl -k -o ${env.JAVA_ZIP} https://nexus.com/nexus/content/repositories/third-party-applications/?? --insecure"
            //echo "=====================>> INSTALLING SPARK! <<====================="
            //sh "curl -k -o ${env.JAVA_ZIP} https://nexus.com/nexus/content/repositories/third-party-applications/?? --insecure"
        }

}

def pullRepos() {
    //BITBUCKET SETUP----------------------------------------
    env.BBS_REPO_URL            = 'https://stash.com:8443/scm/qafrdrnd/dataprocessing.git'
    env.BBS_REPO_PATH           = "${WORKSPACE}/bitbucket/jenkins"
    env.JENKINS_PIPELINES_PATH  = "${env.BBS_REPO_PATH}"

    // Download the repos regardless to pull in any new changes...

    stage("Checkout BBS RM Repo: ${env.BBS_REPO_URL}") {
        //Setup some useful environment variables to used through the pipeline...
        dir ("${env.BBS_REPO_PATH}") {
            checkout([$class: 'GitSCM',
                        branches: [[name: '']],
                        doGenerateSubmoduleConfigurations: false,
                        extensions: [],
                        submoduleCfg: [],
                        //userRemoteConfigs: [[credentialsId: "${params.AD_CREDENTIALS}", url: "${env.BBS_REPO_URL}"]]])
                        userRemoteConfigs: [[credentialsId: "d398a781-1860-4c2b-96b6-dbd5442f9a82", url: "${env.BBS_REPO_URL}"]]])

        }
    }
}

//machine that executes an entire workflow
node('Linux') {
    //GENERIC DIRECTORIES------------------------------------
    env.DOWNLOADS               = "${WORKSPACE}/downloads"
    env.WORKSPACE_BIN           = "${WORKSPACE}/bin"

    //Initialise the pipeline environment, bringing in any required scripts and configuration files...
    //deleteDir()
    pullRepos()

    withConda {
        stage("Running unit-test with pytest") {

            dir("${env.BBS_REPO_PATH}") {
                sh 'conda install pytest -y'
                sh 'conda install ipython -y'
                sh 'conda install numpy -y'
                sh 'conda install pandas -y'
                sh 'conda install pyspark -y'
                sh '''
                    python -m pytest tests/encoding/unit/* --verbose --junit-xml 'results.xml'
                '''
            }
        }
    }
}

字符串

cxfofazt

cxfofazt1#

如果没有记错的话,pytest不会使用通配符 *。我认为你调用--junit-xl的方式也是错误的。如果你想运行tests/encoding/unit文件夹中的所有内容,你应该运行:

python -m pytest tests/encoding/unit --verbose --junit-xml=results.xml

字符串
您可以参考Pytest Usage了解更多信息。

相关问题