Skip to content

A few mypy/test/testcmdline.py::PythonCmdlineSuite::reports.test test fail when lxml is built against libxml2-2.15 #20070

@mgorny

Description

@mgorny

Bug Report

Newer libxml2 versions changed the HTML output to use <meta charset="UTF-8"> instead of the long form. This causes a bunch of mismatches when running tests against lxml built locally (i.e. on Linux distributions), such as:

============================================================== FAILURES ===============================================================
______________________________________________________ testSpecialAnyHtmlReport _______________________________________________________
[gw0] linux -- Python 3.13.9 /tmp/mypy/.venv/bin/python3
data: /tmp/mypy/test-data/unit/reports.test:477:
Failed: Output file tmp/report/html/n.py.html did not match its expected output
-------------------------------------------------------- Captured stderr call ---------------------------------------------------------
Expected:
  <html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> (diff)
  <link rel="stylesheet" type="text/css" href="../mypy-html.css">
  </head>
  <body>
  ...
  </table>
  </body>
  </html>
Actual:
  <html>
  <head>
  <meta charset="UTF-8"> (diff)
  <link rel="stylesheet" type="text/css" href="../mypy-html.css">
  </head>
  <body>
  ...
  </table>
  </body>
  </html>

Alignment of first line difference:
  E: <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  A: <meta charset="UTF-8">
           ^
Update the test output using --update-data (implies -n0; you can additionally use the -k selector to update only specific tests)

The full list of failures is:

FAILED mypy/test/testcmdline.py::PythonCmdlineSuite::reports.test::testUnreachableCodeMarkedAsAny
FAILED mypy/test/testcmdline.py::PythonCmdlineSuite::reports.test::testClassDefIsNotTreatedAsEmpty
FAILED mypy/test/testcmdline.py::PythonCmdlineSuite::reports.test::testTypeVarTreatedAsEmptyLine
FAILED mypy/test/testcmdline.py::PythonCmdlineSuite::reports.test::testHtmlReportMemberExprNoUnanalyzed
FAILED mypy/test/testcmdline.py::PythonCmdlineSuite::reports.test::testSpecialAnyHtmlReport
FAILED mypy/test/testcmdline.py::PythonCmdlineSuite::reports.test::testHtmlReportOnNamespacePackagesWithExplicitBases

Could the test be made more resilient to this difference, please?

To Reproduce

# install libxml2 >= 2.15, e.g.:
pacman -Syu libxml2 libxslt base-devel
uv venv -p 3.13
uv pip install --no-binary lxml -e . -r test-requirements.txt
.venv/bin/pytest mypy/test/testcmdline.py::PythonCmdlineSuite::reports.test

Expected Behavior

Tests passing.

Actual Behavior

Failures as noted above.

Your Environment

  • Mypy version used: 1.18.2 and 2c6c395
  • Python version used: 3.13.9

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-developerIssues relevant to mypy developerstopic-tests

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions