0

I need to publish the result, but could not and have looked through this site and made research but still having issue to publish test result. Do I need to edit certain file similar to the cypress.json to be able to resolve the issue of Publishing. Both Unit test and the coveratge are not publishing any result and files are not found. The code and also the result with error are highlighted below.

Code :

 trigger:
      branches:
        include:
          - #infra-ML-unit-test
    
    variables:
      - group: aws_details #just for backup roles approach
      - group: snowflake-variables
      - group: unit-test-dev
    jobs:
    - job: 'Unit_Test'
      pool:
        vmImage: 'windows-latest' # other options: 'macOS-latest', 'windows-latest', 'ubuntu-latest'
    
      steps:
        - task: UsePythonVersion@0
          inputs:
            versionSpec: '3.8'
          displayName: 'Use Python 3.x'
    
        - task: UsePythonVersion@0
          inputs:
              versionSpec: '3.8'
             
        - script: |
                    pip install virtualenv
                    virtualenv venv
                    source venv/bin/activate  
                    pip install -r requirements.txt
                    python -m pip install --upgrade pip setuptools sqlalchemy snowflake.sqlalchemy
                    echo "$(System.DefaultWorkingDirectory)"
                    echo "$(Build.StagingDirectory)"
                    pip show pandas   
                    python -m pytest  --log-file $SYSTEM_ARTIFACTSDIRECTORY/smoke-qa.log --junitxml=TEST-qa-smoke.xml -rP --excelreport=report.xls  --html=pytest_report.html  --self-contained-html
                    
                    
            #displayName: 'Install python tools'
              
    - job: publish_result
      dependsOn: Unit_Test
      condition: succeededOrFailed()
      steps:  
        - task: PublishTestResults@2
          displayName: 'Publish test result /010.xml'
          inputs:
            testResultsFormat: 'JUnit' # Options: JUnit, NUnit, VSTest, xUnit, cTest
            testResultsFiles: '**/TEST-*.xml' 
            testRunTitle: 010
            mergeTestResults: true
        
    

  

    

Pytest result enter image description here

Unit test and coverage

enter image description here

Is there any file to locate in the repository to update and link with publishing the coverate and test result since the error or warning is mentioning :

**

##[warning]No test result files matching /TEST-*.xml were found.

**

user5820327
  • 181
  • 1
  • 2
  • 15
  • 1
    As an aside, `pip install` accepts a _list_ of packages to install. What's the reason you don't put all these dependencies in `requirements.txt` anyway? Then you'd only need to keep `pip install -r requirements.txt` (or you could save these in a separate file like `requirements-test.txt` and then install from that). – tripleee Mar 19 '22 at 16:52
  • @tripleee. Thanks. I have edited the code and put it in the requirement.txt. – user5820327 Mar 19 '22 at 17:23
  • The generated xml file has a backward slash while the publish report has a forward one. Might be an issue cause of that. – Devang Sanghani Mar 20 '22 at 05:48
  • https://stackoverflow.com/questions/66875892/publish-test-results-task-in-azure-devops – Devang Sanghani Mar 20 '22 at 05:52
  • But I do not understand what you are trying to achieve here. I have tried to change it to backward slash and the same issue, Is tere anyway to know where the xml file is located – user5820327 Mar 20 '22 at 09:14

1 Answers1

1

You have two options:

  1. Install the pytest-azurepipelines package before running the tests:
pip install pytest pytest-azurepipelines
  1. Make the PublishTestResults@2 task start the search from $(Pipeline.Workspace):

    - task: PublishTestResults@2
      displayName: 'Publish test result /010.xml'
      inputs:
        testResultsFormat: 'JUnit'
        testResultsFiles: '$(Pipeline.Workspace)/junit/test-*.xml'
    

For more info see Python: Run tests

KMoraz
  • 14,004
  • 3
  • 49
  • 82
  • Thanks THe pytest-azurepipeline is working but I really need the publishresult to work. I have tried your suggestion on using the $(Pipeline.Workspace). It is not working – user5820327 Mar 20 '22 at 19:08
  • it's a matter of context. Add `workingDirectory: $(Pipeline.Workspace)` to the `script` task and see where the XML file gets created – KMoraz Mar 20 '22 at 22:17