File tree Expand file tree Collapse file tree 3 files changed +15
-26
lines changed Expand file tree Collapse file tree 3 files changed +15
-26
lines changed Original file line number Diff line number Diff line change 55import os
66import re
77import sys
8+ from importlib .util import find_spec as import_exists
9+
10+ import pytest
811
912from mypy import build
1013from mypy .build import Graph
2427)
2528from mypy .test .update_data import update_testcase_output
2629
27- try :
28- pass # import lxml #try just passing for now...
29- except ImportError :
30- lxml_import_failure = True
31-
32-
33- import pytest
34-
3530# List of files that contain test case descriptions.
3631# Includes all check-* files with the .test extension in the test-data/unit directory
3732typecheck_files = find_test_files (pattern = "check-*.test" )
@@ -55,7 +50,7 @@ class TypeCheckSuite(DataSuite):
5550 files = typecheck_files
5651
5752 def run_case (self , testcase : DataDrivenTestCase ) -> None :
58- if lxml_import_failure and os .path .basename (testcase .file ) == "check-reports.test" :
53+ if import_exists ( "lmxl" ) and os .path .basename (testcase .file ) == "check-reports.test" :
5954 pytest .skip ("Cannot import lxml. Is it installed?" )
6055 incremental = (
6156 "incremental" in testcase .name .lower ()
Original file line number Diff line number Diff line change 1010import re
1111import subprocess
1212import sys
13+ from importlib .util import find_spec as import_exists
14+
15+ import pytest
1316
1417from mypy .test .config import PREFIX , test_temp_dir
1518from mypy .test .data import DataDrivenTestCase , DataSuite
1922 normalize_error_messages ,
2023)
2124
22- try :
23- pass # import lxml #try just passing for now...
24- except ImportError :
25- lxml_import_failure = True
26-
27- import pytest
28-
2925# Path to Python 3 interpreter
3026python3_path = sys .executable
3127
@@ -38,7 +34,7 @@ class PythonCmdlineSuite(DataSuite):
3834 native_sep = True
3935
4036 def run_case (self , testcase : DataDrivenTestCase ) -> None :
41- if lxml_import_failure and os .path .basename (testcase .file ) == "reports.test" :
37+ if not import_exists ( "lxml" ) and os .path .basename (testcase .file ) == "reports.test" :
4238 pytest .skip ("Cannot import lxml. Is it installed?" )
4339 for step in [1 ] + sorted (testcase .output2 ):
4440 test_python_cmdline (testcase , step )
Original file line number Diff line number Diff line change 33from __future__ import annotations
44
55import textwrap
6+ from importlib .util import find_spec as import_exists
7+
8+ import pytest
69
710from mypy .report import CoberturaPackage , get_line_rate
811from mypy .test .helpers import Suite , assert_equal
912
10- try :
11- import lxml .etree as etree
12- except ImportError :
13- lxml_import_failure = True
14-
15- import pytest
16-
1713
1814class CoberturaReportSuite (Suite ):
19- @pytest .mark .skipif (lxml_import_failure , reason = "Cannot import lxml. Is it installed?" )
15+ @pytest .mark .skipif (not import_exists ( "lxml" ) , reason = "Cannot import lxml. Is it installed?" )
2016 def test_get_line_rate (self ) -> None :
2117 assert_equal ("1.0" , get_line_rate (0 , 0 ))
2218 assert_equal ("0.3333" , get_line_rate (1 , 3 ))
2319
24- @pytest .mark .skipif (lxml_import_failure , reason = "Cannot import lxml. Is it installed?" )
20+ @pytest .mark .skipif (not import_exists ( "lxml" ) , reason = "Cannot import lxml. Is it installed?" )
2521 def test_as_xml (self ) -> None :
22+ import lxml .etree as etree
23+
2624 cobertura_package = CoberturaPackage ("foobar" )
2725 cobertura_package .covered_lines = 21
2826 cobertura_package .total_lines = 42
You can’t perform that action at this time.
0 commit comments