Azure / pytest-azurepipelines

Plugin for pytest that makes it simple to work with Azure Pipelines
MIT License
112 stars 35 forks source link

Failed to inline CSS styles in coverage reports #90

Open ahemwe opened 10 months ago

ahemwe commented 10 months ago

I want to run pytests on a docker container by means of Azure Pipelines.

Given this pipeline snippet:

- job: Test
  dependsOn: Build  
  steps:
  - checkout: none
  - task: Bash@3
    inputs:
      targetType: 'inline'
      script: |
        mkdir $(Build.SourcesDirectory)/reports
        chmod 777 $(Build.SourcesDirectory)/reports
    displayName: 'Prepare mount folder for reports'
  - task: Bash@3
    inputs:
      targetType: 'inline'
      script: |        
        docker run --rm -v $(Build.SourcesDirectory)/reports:/app/myapp/reports $(image_tag) \
          /bin/bash -c 'pytest . --nunit-xml=reports/test-results.xml --cov --cov-report=xml:reports/coverage.xml --cov-report=html:reports/coverage_html --report-dir=reports/coverage_html'
    displayName: 'Run PyTest'

I get this warning during build: ##[warning]Failed to inline CSS styles in coverage reports. Error: [Errno 2] No such file or directory: '/home/foo/myagent/_work/3/s/reports/coverage_html'

The full output is


/usr/bin/bash /home/foo/myagent/_work/_temp/4c87c14f-c7ef-42aa-84fd-cd74437fb01a.sh
============================= test session starts ==============================
platform linux -- Python 3.10.13, pytest-7.4.3, pluggy-1.3.0
rootdir: /app/myapp
plugins: azurepipelines-1.0.5, cov-4.1.0, nunit-1.0.4, anyio-3.7.1
collected 4 items

app/test_main.py .                                                       [ 25%]
Result Attachments will be stored in LogStore
Run Attachments will be stored in LogStore
##[warning]Failed to inline CSS styles in coverage reports. Error: [Errno 2] No such file or directory: '/home/foo/myagent/_work/3/s/reports/coverage_html'
Reading code coverage summary from '/home/foo/myagent/_work/3/s/reports/coverage.xml'

-- generated Nunit xml file: /app/myapp/reports/test-results.xml ---

---------- coverage: platform linux, python 3.10.13-final-0 ----------
Coverage HTML written to dir reports/coverage_html
Coverage XML written to file reports/coverage.xml

============================== 4 passed in 1.94s ===============================
Async Command Start: Publish test results
Publishing test results to test run '394084'.
TestResults To Publish 4, Test run id:394084
Test results publishing 4, remaining: 0. Test run id: 394084
Published Test Run : https://dev.azure.com/SW4ZF/AZP-352_DivDI_EcoRouting/_TestManagement/Runs?runId=394084&_a=runCharts
Async Command End: Publish test results
Async Command Start: Publish code coverage
Publishing coverage summary data to TFS server.
 Lines- 93 of 164 covered.
 Branches- 0 of 0 covered.
Modifying Cobertura Index file
Publishing code coverage files to TFS server.
Uploading 18 files
File upload succeed.
Published '/home/infra-admin/myagent/_work/3/s/reports/coverage_html' as artifact 'Code Coverage Report_503679'
Async Command End: Publish code coverage
Finishing: Run PyTest

Due to missing inlining of css, the coverage report is broken in AzureDevOps: image

I've tried for hours, but can't find a way to fix this warning.

Any help is highly appreciated. Thanks.

Noam-Microsoft commented 8 months ago

Hi @ahemwe, did you manage to solve this? If you did please let me know how to fix, I encountered the same issue.

ahemwe commented 8 months ago

Unfortunately I didn't manage to fix it.

PeterFogh commented 7 months ago

I have the same problem. And did not find a solution.

However i solved the access to the htmlcov folder by docker run ... sh -c "pytest && chrown -R "$(id -u):$(id -g)" htmlcov"

jankaltenecker commented 7 months ago

I have the same issue and did not find a solution either. I tried to run the tests in a container job and in a docker container with the same result. It seems like the coverage html is written after the plugin is searching for it. In addition I tried to run the tests twice in two steps and deactivate the upload in the first one with –no-coverage-upload flag, but still the same result.

collecting ... collected 7 items

app/backend/tests/test_hubo.py::test_read_users_no_access_token PASSED   [ 14%]
app/backend/tests/test_hubo.py::test_read_users_wrong_approle PASSED     [ 28%]
app/backend/tests/test_hubo.py::test_read_users_correct_approle PASSED   [ 42%]
app/backend/tests/test_users.py::test_users_get_app_roles_no_access_token PASSED [ 57%]
app/backend/tests/test_users.py::test_users_get_app_roles_no_approle PASSED [ 71%]
app/backend/tests/test_users.py::test_users_get_app_roles_user_approle PASSED [ 85%]
Result Attachments will be stored in LogStore
Run Attachments will be stored in LogStore
##[warning]Failed to inline CSS styles in coverage reports. Error: [Errno 2] No such file or directory: '/home/vsts/work/1/s/htmlcov'
Reading code coverage summary from '/home/vsts/work/1/s/coverage.xml'

-------------- generated Nunit xml file: /__w/1/s/test-output.xml --------------

---------- coverage: platform linux, python 3.12.2-final-0 -----------
Coverage HTML written to dir /__w/1/s/htmlcov
Coverage XML written to file /__w/1/s/coverage.xml

============================== 7 passed in 2.83s ===============================