модульный тест с pytest не работает на Jenkins: ОШИБКА: скрипт вернул код завершения 2 - PullRequest
0 голосов
/ 03 февраля 2020

Я выполнил свою команду pytest:

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

и получил следующую ошибку:

ОШИБКА: скрипт вернул код завершения 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'
                        '''
                    }
                }
            }
        }

1 Ответ

0 голосов
/ 04 февраля 2020

Если память работает правильно, pytest не принимает подстановочный знак *. Я думаю, что вы вызвали --junit-xl неправильно. Если вы хотите запустить все в папке tests / encoding / unit, вы должны запустить:

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

Вы можете обратиться к Использование Pytest для получения дополнительной информации.

...