azure pipeline pytest-cov coverage results not displaying properly an throwing a warning - azure-devops

I have a azure pipeline build that runs the following command.
pytest tests --junitxml=junit/test-results.xml --cov --cov-report=xml --cov-report=html
I know this generates the correct coverage report as azure produces it as an artifact which i can download. The problem is that azure seems to have an issue with the coverage report. i get the following warnings:
##[warning]Invalid results file. Make sure the result format of the file '/home/vsts/work/1/s/test-cov.xml' matches 'JUnit' test results format.
##[warning]No code coverage results were found to publish.
In the code coverage tab after the pipeline has finished the html output is there but is is incorrectly displayed.
How do i fix this?

Related

How to see the Code Coverage results in Sonar Qube using Azure DevOps pipelines

I have an .Net Core application along with unit test cases. For that I have configured the Build pipeline in Azure DevOps. In that pipeline I have integrated SonarQube tasks (prepare analysis, run code analysis, and publish quality gate results).
I can see the report in SonarQube server after successful run. But in that report, I didn’t see the Code Coverage Results and Unit test results. Even though I used Cobertura for unit tests.
Your pipeline seems to contain the right steps, so there can be two issues:
1. Code coverage file is not generated (correctly)
The easiest way to validate if the code coverage file is generated correctly, is by publishing it as an artifact. Now check what format the output file is. If there is no output file, please check if you did include /p:CollectCoverage=true --logger trx to the test command. If you are running the build pipeline on Linux, you should also add /p:CoverletOutputFormat=opencover and install the coverlet.collector NuGet package in the .NET Test Project.
2. Code coverage file is not sent to Sonarqube
If you configured step 1 correctly, it is still possible that the generated files are not sent to Sonarqube. The best way to see what is going wrong, is by checking the build logs of the Run Code Analysis and Publish Quality Gate Results steps.
The most common issue, is that Sonarscanner is checking the wrong directory. In the prepare step, please specify where the files are located, like:
sonar.cs.opencover.reportsPaths=$(Build.SourcesDirectory)/**/coverage.opencover.xml
sonar.cs.vstest.reportsPaths=$(Agent.TempDirectory)/*.trx
Build pipeline generates code coverage files would it be coverlet or opencover, the problem is that Azure Devops pipeline creates the reports outside the working directory on the build agent, it uses the _temp folder inside _work whereas soanrquube searches inside the working directory. I am facing this issue with coverlet as well as Visual studio coverage tool. You can read the following 2 threads
https://github.com/coverlet-coverage/coverlet/issues/1399
https://github.com/microsoft/azure-pipelines-tasks/issues/11536.
I posted an issue on snoarqube community site but did not get any response so far. The solution I think is either make the test step in the build pipeline change the directory or configure somewher sonarqube to search the agent build directory _temp which is above the working directory

I get ##[error]No code coverage results were found to publish. when trying to publish my create-react-app code-coverage in Azure DevOps

I am trying to publish code coverage from my create-react-app in Azure devOps even though the coverage is generated when I run test locally I get the following error In azure pipeline when trying to publish the coverage "##[error]No code coverage results were found to publish." find the screenshots of my pipeline config and the error. have being on this for two days now a working solution would greatly be appreciated.
files in the coverage folder:
Coverage
lcov-report(folder)
clover.xml
cobertura-coverage.xml
coverage-final.json
lcov.info
https://drive.google.com/file/d/1J6tRN0RfYWtfc-cJ64Itxwnmlqe8c-BH/view?usp=sharing, https://drive.google.com/file/d/1g-IKWETw2tuXexbk36VPOVpYRD6bCVYf/view?usp=sharing, https://drive.google.com/file/d/1sY6qBc1xEroCfOF3yt6ORbAXPPkr04JE/view?usp=sharing

Coverage returning %NaN% when running unit tests in azure devops

I have a dot net core version: '3.0.100', building on 'ubuntu-latest' and am trying to get code coverage reports.
I have been using Coverlet to generate Cobertura files which can then use the PublishCodeCoverageResults#1 to publish to the Devops pipelines code coverage viewer.
I have used one stage name build for building the project and generating artifacts and published them.
In another stage named unit tests i will be downloading the artifacts and using the artifacts of previous build.
But when I run unit tests by specifying the working directory where these artifacts were downloaded
Everything went fine up to this point,but when it is generating the code coverage reports in the unit test job it is generating NaN% value.
enter image description here
I have tried all possible ways playing with working path directory and restoring the nuget packages.But No Luck None worked for me. I have even searched for this issue,I found one but that didn't worked me
When i tried to run the build and unit tests in one stage itself it successfully generated the code coverage reports,but placing that in another stage and downloading the previous build artifacts made me run into the issue.
How would I achieve this ?

Publish Test Results tasks in Azure DevOps using NUnit

I'm trying to add a 'Publish Test Results' task into my Azure DevOps release pipeline, however, it looks like when I try to publish the .trx file, it's not looking in the correct folder and tries to parse an invalid file format (I'm assuming this is because it can't find the TestResults folder). I can see my file being created here in the Visual Studio Test task logs:
2020-02-19T21:28:57.6557476Z Vstest.console.exe exited with code 0.
2020-02-19T21:28:57.6557819Z:Completed test execution
2020-02-19T21:28:57.6640479Z Test results files: C:\agents\vm1-1_work_temp\TestResults\vm1$_vm1_2020-02-19_21_28_31.trx
However, in my Publish Test Results task logs, I get this error:
2020-02-19T21:28:59.7249456Z [command]C:\agents\vm1-1_work_tasks\PublishTestResults_0b0f01ed-7dde-43ff-9cbb-e48954daf9b1\2.164.3\modules\TestResultsPublisher.exe #C:\agents\vm1-1_work_temp\d793cb80-535e-11ea-9ab4-8f1d738f183d.txt
2020-02-19T21:29:00.5600855Z ##[warning]Failed to parse result files: Invalid file format.
This is what my Test Run and Publish Test Results tasks look like....can anyone point out what I am doing wrong here? I've seen people say that I don't need to add this task, but I am unable to see the Test Results tab in the pipeline, I can only see the .trx file attached to the task (see below).
TestResultsFormat is an alias for the testRunner input name. It seems you are using VSTest testRunner, so in Publish Test Results task, you should choose VSTest in TestResultsFormat.

Missing "Code Coverage" tab on Python project

I have a Python project hosted on GitHub, which I test using Azure Pipelines (here is a link to the configuration).
I am running unit tests with pytest and get coverage results, which I upload in my pipeline. I get an overall code coverage percentage in the pipeline execution summary (example), but I don't see a "Code Coverage" tab that contains the details of which lines are covered. The build artifacts contain the HTML code coverage report, which contains this information, but it'd be nicer to see it in the pipeline run page itself.
Here is the invocation of pytest:
pytest tests --doctest-modules --junitxml=junit/test-results.xml
--cov=callgraph --cov-report=xml --cov-report=html
What am I missing?
that doesnt work like that, unfortunately. at least that was the case 6 months ago.
https://github.com/Microsoft/azure-pipelines-tasks/issues/7703