Jenkinsfile junit testresult None of the test reports contained any result

24 Views Asked by At

I can't get the coverage.xml result however the file created and the path is also fine. When I check the file, its print out Yes. I tried everything already what I found: **/*xml, *.xml Same error... I also tried junit '**/*.xml', junit '*xml', junit 'coverage.xml'

         post {
            always {
                script {
                    if (fileExists('coverage.xml')) {
                        echo 'Yes'
                    } else {
                        echo 'No'
                    }
                }
                junit skipPublishingChecks: true, testResults: 'coverage.xml'
            }
        }

enter image description here

This script create the test results:

echo "Start tests..."
coverage run -m pytest

echo "Omitted all test files and __init__.py from report."
echo "Files with 100% coverages skipped from the report."
OMITTED=test*,tests/*,**/__init__.py,main.py,config/*
coverage report -m --fail-under=97 --skip-covered --omit=$OMITTED > coverage.log
cat coverage.log
export COVERAGE=$(awk '$1 == "TOTAL" {print $NF+0}' coverage.log)

coverage html --skip-covered --omit=$OMITTED
echo "HTML report created at: 'htmlcov/index.html'"

coverage json --omit=$OMITTED
coverage xml --skip-empty --omit=$OMITTED

Everything created well, I have .json, .log, .xml and .html version. Any idea how to resolve this issue or how can I display the report on Jenkins?


Update: When I execute the test using the bellow command, the coverage.xml report accepted and displayed in the Jenkins UI. I can narrow down the error to this line:
coverage xml --skip-empty --omit=$OMITTED

This code works fine:

        stage('Integration and Unit testing') {
            steps {
                sh 'pytest --junitxml coverage.xml .'
            }
            post {
                always {
                    junit 'coverage.xml'
                }
            }
        }
0

There are 0 best solutions below