Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail on no test file for PublishTestResults@2 #13275

Open
derekendres opened this issue Jul 13, 2020 · 32 comments
Open

Fail on no test file for PublishTestResults@2 #13275

derekendres opened this issue Jul 13, 2020 · 32 comments

Comments

@derekendres
Copy link

Note

Issues in this repo are for tracking bugs, feature requests and questions for the tasks in this repo

For a list:
https://github.com/Microsoft/azure-pipelines-tasks/tree/master/Tasks

If you have an issue or request for the Azure Pipelines service, use developer community instead:

https://developercommunity.visualstudio.com/spaces/21/index.html )

Required Information

Entering this information will route you directly to the right team and expedite traction.

Question, Bug, or Feature?
Type: Feature

Enter Task Name: PublishTestResults@2

list here (V# not needed):
https://github.com/Microsoft/azure-pipelines-tasks/tree/master/Tasks

Environment

  • Server - Azure Pipelines or TFS on-premises?

    • If using Azure Pipelines, provide the account name, team project name, build definition name/build number:

https://dev.azure.com/osieng/engineering/_build/results?buildId=103053&view=logs&j=846ec57a-2bea-5833-7752-007160b95b9a&t=d1056ef1-5a88-52db-be24-b861f9682b72

  • Agent - Hosted or Private:

    • If using Hosted agent, provide agent queue name:

      linux:
      imageName: ubuntu-latest
      windows:
      imageName: windows-latest

Issue Description

When publishing a test result, if there is no test result file, this task gives a warning that is eaten by a success indication. It should flag as a warning that it didn't actually publish the result and ideally there should be an option to fail if the test file doesn't exist.

Task logs

Starting: Publish test results

Task : Publish Test Results
Description : Publish test results to Azure Pipelines
Version : 2.171.0
Author : Microsoft Corporation
Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/test/publish-test-results

/usr/bin/dotnet --version
3.1.301
##[warning]No test result files matching **/test-*.xml were found.
Finishing: Publish test results

Troubleshooting

Checkout how to troubleshoot failures and collect debug logs: https://docs.microsoft.com/en-us/vsts/build-release/actions/troubleshooting

Error logs

[Insert error from the logs here for a quick overview]

@csurfleet
Copy link

This would be incredibly useful, we're using bash scripts between each test task at the moment

@BarsikV
Copy link

BarsikV commented Jul 27, 2020

My team and I would appreciate this feature very much, too!

This would be incredibly useful, we're using bash scripts between each test task at the moment

Would you mind sharing your script?

@bneumann
Copy link

bneumann commented Sep 30, 2020

This would be incredibly useful, we're using bash scripts between each test task at the moment

Yeah if I need to script my way around problems like that I really don't need these tasks at all. I prefer a fix for this :)

@ShreyasRmsft ShreyasRmsft removed their assignment Sep 30, 2020
@navin22 navin22 removed their assignment Oct 1, 2020
@navin22
Copy link
Member

navin22 commented Oct 1, 2020

Adding @shailesh-sk

@xncbf
Copy link

xncbf commented Nov 16, 2020

Anybody working on this issue? This option is essential

@walliski
Copy link

Coming in yet half year later.

This would be really essential for the pipelines I am working on. In the current setup I want to do, I would not want to fail the build based on the exit status of the tests step, but continue and later use the published test results further down in the pipeline. This means that both this task, and the Powershell task that runs the tests is set to not fail the build on failure. To safeguard from the testrunner failing completely and not running any tests at all, I would need this task to fail in case it cannot find any test result files!

walliski added a commit to walliski/azure-pipelines-tasks that referenced this issue May 21, 2021
Adds an option that lets the user configure the task to fail in case no
test result files have been found. This serves as a safeguard to make
sure that the test-run task and this task has been configured properly
to find the test result files.

Solves microsoft#13275
walliski added a commit to walliski/azure-pipelines-tasks that referenced this issue May 21, 2021
Adds an option that lets the user configure the task to fail in case no
test result files have been found. This serves as a safeguard to make
sure that the test-run task and this task has been configured properly
to find the test result files.

Solves microsoft#13275
walliski added a commit to walliski/azure-pipelines-tasks that referenced this issue May 21, 2021
Adds an option that lets the user configure the task to fail in case no
test result files have been found. This serves as a safeguard to make
sure that the test-run task and this task has been configured properly
to find the test result files.

Solves microsoft#13275
@jmhon08
Copy link

jmhon08 commented Jun 23, 2021

I would like to see this as well. @shailesh-sk the PR is waiting your review

@shailesh-sk
Copy link
Contributor

shailesh-sk commented Jun 24, 2021

@jmhon08 PR looks good to me, added upadhyayap@github.com to cherry pick this change.

@ghost
Copy link

ghost commented Jun 30, 2021

A bit late to the party, but I'm looking forward to seeing this added as well.

@jmhon08
Copy link

jmhon08 commented Jul 13, 2021

@upadhyayap any idea when this will be merged?

@walliski
Copy link

@shailesh-sk @upadhyayap

Did we get anywhere with #14868 ?

@mathiash98
Copy link

This is an essential feature... It should at least make a warning if not fail completely at the "Publish Test Results task"

@LynxJ
Copy link

LynxJ commented Dec 7, 2021

Would really like to see this feature implemented

@ColeSiegelTR
Copy link

Also looking for this, seems fundamental

@mathiash98
Copy link

mathiash98 commented Feb 1, 2022

We ended up using follow bash script tasks which first check if test result file exists, then check if number of results are more than 0:

We rely on running tests inside a docker compose as we also test with database. But if you purely rely on the VSTest task you can use the argument minimumExpectedTests https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/test/vstest?view=azure-devops#arguments to fail if there are no tests run.

- bash: |
    if [ $(test_results_host_folder)**/*.trx ] && [ $(grep -E "<UnitTestResult" $(test_results_host_folder)**/*.trx -c) -gt 0 ]; then
      echo "##vso[task.setVariable variable=TESTRESULTFOUND]true"
    fi
  displayName: Check if test results file & results >= 1
- script: |
      echo No test result found
      exit 1
  displayName: No test result found
  condition: ne(variables.TESTRESULTFOUND, 'true')

@ColeSiegelTR
Copy link

been another 4 months any plans to fix this?

@b055man
Copy link

b055man commented Jun 22, 2022

Coming in yet half year later.

This would be really essential for the pipelines I am working on. In the current setup I want to do, I would not want to fail the build based on the exit status of the tests step, but continue and later use the published test results further down in the pipeline. This means that both this task, and the Powershell task that runs the tests is set to not fail the build on failure. To safeguard from the testrunner failing completely and not running any tests at all, I would need this task to fail in case it cannot find any test result files!

The problem is the PublishTestResults succeeds not only if there are no test results but also if it fails to parse the test results, e.g. if a failed test case produces output that cannot be parsed.
This's just happened in our environment when some test cases were failing but this was not captured by the pipeline.
image

Yes, you can make a workaround to address this (like check and store result of the test command and fail the pipeline later etc.) but that's only if you know that the PublishTest task is unreliable beforehand.

To me this sounds like a bug, not an enhancement!

@danon
Copy link

danon commented Jun 29, 2022

I think it would make more sense if the job would fail by default, and maybe add an option to explicitly silence it.

@willieowens
Copy link

Starting: Publish test result to ADO
==============================================================================
Task         : Publish Test Results
Description  : Publish test results to Azure Pipelines
Version      : 2.203.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/test/publish-test-results
==============================================================================
/usr/bin/dotnet --version
6.0.302
Result Attachments will be stored in LogStore
Run Attachments will be stored in LogStore
No Result Found to Publish '/home/vsts/work/1/s/cypress-results/test-output-57f4d8778c4987bda6a1790eaa703782.xml'.
Async Command Start: Publish test results
Publishing test results to test run '376211378'.
TestResults To Publish 108, Test run id:376211378
Test results publishing 108, remaining: 0. Test run id: 376211378
Published Test Run : https://msasg.visualstudio.com/XXXXXXXX/_TestManagement/Runs?runId=376211378&_a=runCharts
##[warning]Intermittent failure attempting to call the restapis System.Threading.Tasks.Task`1[Microsoft.TeamFoundation.TestManagement.WebApi.TestRunStatistic] <GetTestRunSummaryAsync>b__0(). Retry attempt 0. Exception: Run summary is not available, It is recommended to try again after 1 sec. 
##[warning]Intermittent failure attempting to call the restapis System.Threading.Tasks.Task`1[Microsoft.TeamFoundation.TestManagement.WebApi.TestRunStatistic] <GetTestRunSummaryAsync>b__0(). Retry attempt 1. Exception: Run summary is not available, It is recommended to try again after 1 sec. 
##[warning]Intermittent failure attempting to call the restapis System.Threading.Tasks.Task`1[Microsoft.TeamFoundation.TestManagement.WebApi.TestRunStatistic] <GetTestRunSummaryAsync>b__0(). Retry attempt 2. Exception: Run summary is not available, It is recommended to try again after 1 sec. 
TestRunDataPublisher.DoesRunsContainsFailures: Exception occured using test run summary api System.AggregateException: One or more errors occurred. (Run summary is not available, It is recommended to try again after 1 sec.)
 ---> Microsoft.TeamFoundation.TestManagement.WebApi.TestObjectNotFoundException: Run summary is not available, It is recommended to try again after 1 sec.
   at Microsoft.TeamFoundation.TestClient.PublishTestResults.RetryHelper.Retry[T](Func`1 action, Func`2 timeDelayInterval, Func`2 shouldRetryOnException)
   at Microsoft.TeamFoundation.TestClient.PublishTestResults.TestRunPublisher.GetTestRunSummaryAsync(String projectName, Int32 testRunId, Boolean allowRetry, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
   at Microsoft.VisualStudio.Services.Agent.Worker.TestResults.TestRunDataPublisherHelper.DoesRunsContainsFailures(IList`1 testRuns, String projectName)
##[warning]TestRunDataPublisher.DoesRunsContainsFailures: Validating if test run is failed or succeeded based on summary where calulation of summary is not in completed state.
TestRunPublisher.IsTestRunFailed: Getting test run summary with run id: 376211378 using stats api
TestRunPublisher.IsTestRunFailed: checking if test run is failed using run summary input
Async Command End: Publish test results
Finishing: Publish test result to ADO

Somewhat different, but we just had a live site because although many of our tests failed, this task had some internal error reporting/fetching the test results. Not good... We need to correct the error handling in this task.

walliski added a commit to walliski/azure-pipelines-tasks that referenced this issue Nov 16, 2022
Adds an option that lets the user configure the task to fail in case no
test result files have been found. This serves as a safeguard to make
sure that the test-run task and this task has been configured properly
to find the test result files.

Solves microsoft#13275
@github-actions
Copy link

This issue is stale because it has been open for 180 days with no activity. Remove the stale label or comment on the issue otherwise this will be closed in 5 days

@github-actions github-actions bot added the stale label Jan 22, 2023
@walliski
Copy link

This issue is stale because it has been open for 180 days with no activity. Remove the stale label or comment on the issue otherwise this will be closed in 5 days

@github-actions github-actions bot removed the stale label Jan 22, 2023
@AurimasNav
Copy link

I'd love to see this fail by default if no test files are found.

@jamesstojan1
Copy link

This would be really helpful. The default assumption when publishing non existent files should be to error out.

@coffeebe4code
Copy link

nearly 3 years this has been opened?

Everyone going to be here for its 3rd birthday in July?

@dts12263
Copy link

dts12263 commented Apr 3, 2023

I contacted Microsoft support through my work and was suggested to simply use the bash workaround.....I also share this frustration. So it does not seem like there are any plans to fix this bug. It's astonishing Microsoft is willingly letting this bug persist and relying on workarounds suggested by other users. Then they left me with a survey asking how well they addressed my problem!! Hysterical

@abatishchev
Copy link

Bump.

@xncbf
Copy link

xncbf commented Sep 7, 2023

I got tired of waiting and found the solution myself.
The root cause I've encountered is that the failure signal appears to be ignored if there is another command on the next line that runs pytest.
I solved it by receiving the signal from the line immediately following the test and processing it directly, as follows.

pipenv run pytest --junitxml=junit/test-results.xml --cov=. --cov-report=html
EXIT_CODE=$?
if [ $EXIT_CODE -ne 0 ]; then
exit $EXIT_CODE
fi

Copy link

github-actions bot commented Mar 5, 2024

This issue is stale because it has been open for 180 days with no activity. Remove the stale label or comment on the issue otherwise this will be closed in 5 days

@github-actions github-actions bot added the stale label Mar 5, 2024
@ChristianStadelmann
Copy link

This issue is not stale, but I guess the bot is…

@github-actions github-actions bot removed the stale label Mar 5, 2024
@KevinPartingtonTR
Copy link

Microsoft folks, if this is something you don't plan to fix, you should close this issue as not planned so we know. Thanks!

@dts12263
Copy link

dts12263 commented Mar 18, 2024 via email

@riQQ
Copy link

riQQ commented May 22, 2024

This is available with version 2.228.0+ via setting the input failTaskOnMissingResultsFile to true. It was implemented by #18931 and is also documented on learn.microsoft.com.

- task: PublishTestResults@2
  inputs:
    failTaskOnMissingResultsFile: true # boolean. Fail if no result files are found. Default: false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests