简体   繁体   English

在 Jenkins 中运行 python 单元测试

[英]Running python Unittest in Jenkins

I am a new programmer.我是一个新程序员。 I have a simple calculator python code which i want to deploy using Jenkins pipeline.我有一个简单的计算器 python 代码,我想使用 Jenkins 管道进行部署。

There is a python unittest file in my git repo named "unit-test".在我的 git 存储库中有一个名为“unit-test”的 python unittest 文件。 I tried to execute unit test as mentioned in the stage(test) , but it is not working.我尝试执行stage(test)中提到的单元测试,但它不起作用。

stage('Test') {
        steps {
            echo 'Testing..'
            python setup.py nosetests --with-xunit
            nosetests unit-test.py  

Can someone please help me fix the issue.有人可以帮我解决这个问题。

My github repo url: https://github.com/Tasfiq23/Devops_assessment_2.git/我的 github 回购 url: https://github.com/Tasfiq23/Devops_assessment_2.git/

I have re-created your pipeline in Jenkins and it got success.我已经在 Jenkins 中重新创建了您的管道,它取得了成功。

Pipeline Script流水线脚本

pipeline {
agent any
stages {
    stage ('GIT Checkout'){
        steps {
            git changelog: false, poll: false, url: 'https://github.com/Tasfiq23/Devops_assessment_2.git'
        }
    }
    
    stage('build') {
  steps {
    sh 'pip install -r requirements.txt'
  }
}
    stage ('Test'){
        steps {
            sh 'python unit-test.py'
        }
    }
}
}

Output: Output:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM