Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

execute pytest using pipeline in Jenkins

currently i execute my tests in pytest by command like "pytest mytest.py" copied to inside form field "Execute Windows batch command" in the job Jenkins. I want to change my job to execute it by pipeline. I try a lot of code from Stackoverflow but any one of them doesn't work. Do you have a simple code to run regresion tests with pytest connection to Git?

like image 497
pyMike Avatar asked Dec 31 '19 09:12

pyMike


People also ask

Can we use Python in Jenkins pipeline?

You're now ready to create your Pipeline that will automate building your Python application with PyInstaller in Jenkins. Your Pipeline will be created as a Jenkinsfile , which will be committed to your locally cloned Git repository ( simple-python-pyinstaller-app ).


Video Answer


2 Answers

I'll suggest you to use : 'Pyenv Pipeline' plugin (https://plugins.jenkins.io/pyenv-pipeline)

stage("test PythonEnv") {

    withPythonEnv('python3') {
        sh 'pip install pytest'
        sh 'pytest mytest.py'
    }
}
like image 116
EricD Avatar answered Oct 23 '22 04:10

EricD


If you are just after running it as simple Jenkins pipeline (say scripted for now), you can run something like below?

node
{
   stage('Run pytest') 
   {
       bat "pytest mytest.py"
   }    
}
like image 43
vinWin Avatar answered Oct 23 '22 03:10

vinWin