Framework Mode - Running PyTest in Jenkins
Folder Structure for PyTest Project
project-root/ ├── tests/ │ ├── test_example.py │ └── conftest.py ├── src/ │ └── application_code.py ├── pytest.ini ├── requirements.txt └── Jenkinsfile
project-root/ ├── tests/ │ ├── test_example.py │ └── conftest.py ├── src/ │ └── application_code.py ├── pytest.ini ├── requirements.txt └── Jenkinsfile
tests/ folder, contains test cases using PyTest syntax.conftest.py for setup and teardown reusable code.src/ folder, the code under test.pytest.ini for PyTest settings and markers.Jenkinsfile defines Jenkins build and test steps.--junitxml=reports/result.xml), and test paths.pipeline {
agent any
stages {
stage('Install') {
steps {
sh 'python -m venv venv'
sh './venv/bin/pip install -r requirements.txt'
}
}
stage('Test') {
steps {
sh './venv/bin/pytest --junitxml=reports/result.xml'
}
}
}
post {
always {
junit 'reports/result.xml'
archiveArtifacts artifacts: 'reports/**', allowEmptyArchive: true
}
}
}
result.xml for Jenkins to parse test results.Where in this framework structure would you add a new fixture to set up a database connection for tests?