Azure / pytest-azurepipelines

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

Fix broken styling of coverage report in Azure DevOps portal `<iframe>` #94

Open frazar opened 6 months ago

frazar commented 6 months ago

The Azure DevOps uses an <iframe> tag to sandbox the automatically-generated HTML coverage report. This results in bad formatting because in the <iframe>:

See for example #36.

This PR addresses the last point, by replacing the main tag in the HTML coverage report with an innocuous div tag. The static CSS stylesheet is updated accordingly.

My test strategy has been the following:

git checkout master
./run.sh # Afterwards, open wrapper.html with a browser to see the outcome BEFORE
git checkout fzardi/fix-main-tag
./run.sh # Afterwards, open wrapper.html with a browser to see the outcome AFTER

where "run.sh" is the following bash script (NOTE: you might need to fix the path to the second file embedded by the ifram):

#!/usr/bin/env bash

set -uexo pipefail

rm -f wrapper.html
rm -rf .venv
rm -rf htmlcov

python -m venv .venv
source .venv/bin/activate

pip install .
pip install pytest-cov

pytest tests -v -m "not testfail" --cov --cov-report=html

cat <<EOF > wrapper.html
<!DOCTYPE html>
    <head>
        <style>
            iframe {
                height: 400px;
                width: 800px;
                background: #f8f8f8;
            }
        </style>
    </head>

    <body>
        <iframe sandbox="" src="./htmlcov/index.html"></iframe>
        <iframe sandbox="" src="./htmlcov/d_a44f0ac069e85531_test_azurepipelines_py.html"></iframe>
    </body>
</html>
EOF

deactivate
rm -rf .venv

# Now open the "wrapper.html" file with a browser for a preview
BEFORE AFTER
before after

Closes #36.