1

I'm working on a project where code coverage needs to display in Sonarqube. We are framing dockerfile.test where at ENTRYPOINT nosetests is provided. setup.cfg file is created putting all required nosetests plugins. Then sonar-project.properties file has been created for sonarqube reference. And a stage named "Test/Sonar" is created in jenkins ,

below has the script of all above mentioned files.

FROM python:3.7-slim
RUN apt-get update && apt-get install -y --no-install-recommends gcc gfortran perl libtest-utf8-perl \
libtest-file-perl libtest-files-perl cpanminus build-essential curl libcurl4-openssl-dev libssl-dev \
gfortran liblzma-dev libblas-dev liblapack-dev libpq-dev procps libldap2-dev libsasl2-dev ldap-utils git
RUN cpanm install File::Copy::Recursive
RUN pip install numpy && pip install scipy pandas scikit-learn
COPY requirements.txt /requirements.txt
RUN pip install --no-cache-dir -r /requirements.txt 
COPY test_requirements.txt /test_requirements.txt
RUN pip install --no-cache-dir -r /test_requirements.txt 
COPY . /app
WORKDIR /app
#Install Mim
RUN python mim-python-client/setup.py install
RUN mkdir -p /local/tmp/mim-cache
RUN chmod -R 777 /local/tmp/mim-cache
#Install Extract
WORKDIR /app/extract-rules
RUN bash --posix ./dev/build.sh
RUN cp ./bin/python_parser.py /opt/extract/bin/
WORKDIR /app/backend/worker
ENV PYTHONUNBUFFERED=1
ENTRYPOINT nosetests
[nosetests]
verbose=3 
with-xunit=1
xunit-file=nosetests.xml
with-coverage=1
cover-xml=1
cover-package=.
exclude-dir=test
sonar.projectKey=IPA_NIP
sonar.projectName=IPA_NIP
sonar.projectVersion=1.0.0
sonar.language=py
sonar.sourceEncoding=UTF-8
sonar.python.coverage.reportPaths=coverage.xml
sonar.python.xunit.reportPaths=nosetests.xml
sonar.python.xunit.skipDetails=false
sonar.sources=backend/orch, backend/worker, webserver/pinap 
sonar.typescript.lcov.reportPaths=coverage/IPA_NIP/lcov.info
sonar.python.coveragePlugin=cobertura
 stage ('Test/Sonar') {
 
 steps {
 // This specific examples expects that you have a Dockerfile.test that you build, then run to generate test results.
 // Since different projects can vary however, you should make sure you use the solution that works best for you.
 sh "docker build . -f Dockerfile.test -t python-test:${BUILD_ID}"
 sh '''docker run -u 50001255:25 -v "$(pwd)":/app python-test:${BUILD_ID}'''
 sh '''sed -i 's|filename="|filename="'"$(pwd)"'/|' coverage.xml'''
 
 sonarScan('Sonar')
 }
 // Make test results visible in Jenkins UI if the install step completed successfully
 post {
 success {
 junit testResults: 'nosetests.xml', allowEmptyResults: true
 }
 }
 }

I couldn't able to find why I'm getting 0% coverage at sonarqube.

dockerfile.test is executing without any error. I'm getting status about tests (Unit test) as OK. But I'm getting a warning

WARN: The report '/apps/dftjenkins/jenkins_node/workspace/v_AutomationAuthenticationScript/coverage.xml' seems to be empty, ignoring. '{}'
org.sonar.plugins.python.EmptyReportException: null

Could anyone help me out with my queries?

asked Feb 23, 2022 at 11:02

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.