Skip to content

Skip tests that depend on lxml if not installed #12813

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

Merged
merged 1 commit into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions mypy/test/testcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
from mypy.errors import CompileError
from mypy.semanal_main import core_modules

try:
import lxml # type: ignore
except ImportError:
lxml = None

import pytest

# List of files that contain test case descriptions.
typecheck_files = [
Expand Down Expand Up @@ -117,6 +123,8 @@ class TypeCheckSuite(DataSuite):
files = typecheck_files

def run_case(self, testcase: DataDrivenTestCase) -> None:
if lxml is None and os.path.basename(testcase.file) == 'check-reports.test':
pytest.skip("Cannot import lxml. Is it installed?")
incremental = ('incremental' in testcase.name.lower()
or 'incremental' in testcase.file
or 'serialize' in testcase.file)
Expand Down
9 changes: 9 additions & 0 deletions mypy/test/testcmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
assert_string_arrays_equal, normalize_error_messages, check_test_output_files
)

try:
import lxml # type: ignore
except ImportError:
lxml = None

import pytest

# Path to Python 3 interpreter
python3_path = sys.executable

Expand All @@ -35,6 +42,8 @@ class PythonCmdlineSuite(DataSuite):
native_sep = True

def run_case(self, testcase: DataDrivenTestCase) -> None:
if lxml is None and os.path.basename(testcase.file) == 'reports.test':
pytest.skip("Cannot import lxml. Is it installed?")
for step in [1] + sorted(testcase.output2):
test_python_cmdline(testcase, step)

Expand Down
10 changes: 10 additions & 0 deletions mypy/test/testreports.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,21 @@
from mypy.report import CoberturaPackage, get_line_rate


try:
import lxml # type: ignore
except ImportError:
lxml = None

import pytest


class CoberturaReportSuite(Suite):
@pytest.mark.skipif(lxml is None, reason="Cannot import lxml. Is it installed?")
def test_get_line_rate(self) -> None:
assert_equal('1.0', get_line_rate(0, 0))
assert_equal('0.3333', get_line_rate(1, 3))

@pytest.mark.skipif(lxml is None, reason="Cannot import lxml. Is it installed?")
def test_as_xml(self) -> None:
import lxml.etree as etree # type: ignore

Expand Down