From 5ac89eafc68eb3f76f4ae8d8a54fea61a3c545e2 Mon Sep 17 00:00:00 2001 From: Lawrence Chan Date: Tue, 4 Aug 2020 14:01:21 -0500 Subject: [PATCH 1/5] Use pytest Node.from_parent if available --- mypy/test/data.py | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/mypy/test/data.py b/mypy/test/data.py index 5484fd99e944..8141b10c8373 100644 --- a/mypy/test/data.py +++ b/mypy/test/data.py @@ -10,7 +10,18 @@ import sys import pytest # type: ignore # no pytest in typeshed -from typing import List, Tuple, Set, Optional, Iterator, Any, Dict, NamedTuple, Union +from typing import ( + Any, + Callable, + Dict, + Iterator, + List, + NamedTuple, + Optional, + Set, + Tuple, + Union, +) from mypy.test.config import test_data_prefix, test_temp_dir, PREFIX @@ -510,7 +521,10 @@ def pytest_pycollect_makeitem(collector: Any, name: str, # Non-None result means this obj is a test case. # The collect method of the returned DataSuiteCollector instance will be called later, # with self.obj being obj. - return DataSuiteCollector(name, parent=collector) + if hasattr(DataSuiteCollector, 'from_parent'): + return DataSuiteCollector.from_parent(parent=collector, name=name) + else: + return DataSuiteCollector(name=name, parent=collector) return None @@ -535,14 +549,22 @@ def split_test_cases(parent: 'DataSuiteCollector', suite: 'DataSuite', for i in range(1, len(cases), 6): name, writescache, only_when, platform_flag, skip, data = cases[i:i + 6] platform = platform_flag[1:] if platform_flag else None - yield DataDrivenTestCase(parent, suite, file, - name=add_test_name_suffix(name, suite.test_name_suffix), - writescache=bool(writescache), - only_when=only_when, - platform=platform, - skip=bool(skip), - data=data, - line=line_no) + if hasattr(DataDrivenTestCase, 'from_parent'): + creator = DataDrivenTestCase.from_parent # type: Callable[..., DataDrivenTestCase] + else: + creator = DataDrivenTestCase + yield creator( + parent=parent, + suite=suite, + file=file, + name=add_test_name_suffix(name, suite.test_name_suffix), + writescache=bool(writescache), + only_when=only_when, + platform=platform, + skip=bool(skip), + data=data, + line=line_no, + ) line_no += data.count('\n') + 1 From 1fde3b8746d0d8ca9412c7a5cdb88488ea4e3bf1 Mon Sep 17 00:00:00 2001 From: Lawrence Chan Date: Tue, 4 Aug 2020 15:24:40 -0500 Subject: [PATCH 2/5] Use pytest Node.from_parent unconditionally (requires pytest 5.4+) --- mypy/test/data.py | 24 +++--------------------- pytest.ini | 2 +- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/mypy/test/data.py b/mypy/test/data.py index 8141b10c8373..a394f8dc8fe5 100644 --- a/mypy/test/data.py +++ b/mypy/test/data.py @@ -10,18 +10,7 @@ import sys import pytest # type: ignore # no pytest in typeshed -from typing import ( - Any, - Callable, - Dict, - Iterator, - List, - NamedTuple, - Optional, - Set, - Tuple, - Union, -) +from typing import List, Tuple, Set, Optional, Iterator, Any, Dict, NamedTuple, Union from mypy.test.config import test_data_prefix, test_temp_dir, PREFIX @@ -521,10 +510,7 @@ def pytest_pycollect_makeitem(collector: Any, name: str, # Non-None result means this obj is a test case. # The collect method of the returned DataSuiteCollector instance will be called later, # with self.obj being obj. - if hasattr(DataSuiteCollector, 'from_parent'): - return DataSuiteCollector.from_parent(parent=collector, name=name) - else: - return DataSuiteCollector(name=name, parent=collector) + return DataSuiteCollector.from_parent(parent=collector, name=name) return None @@ -549,11 +535,7 @@ def split_test_cases(parent: 'DataSuiteCollector', suite: 'DataSuite', for i in range(1, len(cases), 6): name, writescache, only_when, platform_flag, skip, data = cases[i:i + 6] platform = platform_flag[1:] if platform_flag else None - if hasattr(DataDrivenTestCase, 'from_parent'): - creator = DataDrivenTestCase.from_parent # type: Callable[..., DataDrivenTestCase] - else: - creator = DataDrivenTestCase - yield creator( + yield DataDrivenTestCase.from_parent( parent=parent, suite=suite, file=file, diff --git a/pytest.ini b/pytest.ini index 81586a23708f..f90d92934aba 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,6 +1,6 @@ [pytest] # testpaths is new in 2.8 -minversion = 2.8 +minversion = 5.4 testpaths = mypy/test mypyc/test From 472089c4d1e0c3bd461f30a6543fce50fe2e9400 Mon Sep 17 00:00:00 2001 From: Lawrence Chan Date: Tue, 4 Aug 2020 15:43:43 -0500 Subject: [PATCH 3/5] Bump pytest test requirements --- test-requirements.txt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test-requirements.txt b/test-requirements.txt index 073b8cde5712..fd052aaad170 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -5,11 +5,10 @@ flake8-bugbear; python_version >= '3.5' flake8-pyi>=20.5; python_version >= '3.6' lxml>=4.4.0 psutil>=4.0 -pytest==5.3.2 -pytest-xdist>=1.22 -# pytest-xdist depends on pytest-forked and 1.1.0 doesn't install clean on macOS 3.5 -pytest-forked>=1.0.0,<1.1.0 -pytest-cov>=2.4.0 +pytest>=6.0.1,<7.0.0 +pytest-xdist>=1.34.0,<2.0.0 +pytest-forked>=1.3.0,<2.0.0 +pytest-cov>=2.10.0,<3.0.0 typing>=3.5.2; python_version < '3.5' py>=1.5.2 virtualenv<20 From d8bdd58f855ac333e96005592a112e453c4d413c Mon Sep 17 00:00:00 2001 From: Lawrence Chan Date: Tue, 4 Aug 2020 16:34:20 -0500 Subject: [PATCH 4/5] Require pytest 6.0 and remove unused type ignores --- mypy/test/data.py | 15 +++++++++------ mypy/test/helpers.py | 2 +- mypy/test/testfinegrained.py | 2 +- mypy/test/testipc.py | 2 +- mypy/test/testparse.py | 2 +- mypy/test/testpep561.py | 2 +- mypy/test/testpythoneval.py | 2 +- mypyc/test/testutil.py | 2 +- pytest.ini | 3 +-- test-requirements.txt | 2 +- 10 files changed, 18 insertions(+), 16 deletions(-) diff --git a/mypy/test/data.py b/mypy/test/data.py index a394f8dc8fe5..19fb8d00a818 100644 --- a/mypy/test/data.py +++ b/mypy/test/data.py @@ -9,7 +9,7 @@ from abc import abstractmethod import sys -import pytest # type: ignore # no pytest in typeshed +import pytest from typing import List, Tuple, Set, Optional, Iterator, Any, Dict, NamedTuple, Union from mypy.test.config import test_data_prefix, test_temp_dir, PREFIX @@ -160,9 +160,12 @@ def parse_test_case(case: 'DataDrivenTestCase') -> None: case.expected_fine_grained_targets = targets -class DataDrivenTestCase(pytest.Item): # type: ignore # inheriting from Any +class DataDrivenTestCase(pytest.Item): """Holds parsed data-driven test cases, and handles directory setup and teardown.""" + # Override parent member type + parent = None # type: DataSuiteCollector + input = None # type: List[str] output = None # type: List[str] # Output for the first pass output2 = None # type: Dict[int, List[str]] # Output for runs 2+, indexed by run number @@ -266,7 +269,7 @@ def repr_failure(self, excinfo: Any, style: Optional[Any] = None) -> str: # call exit() and they already print out a stack trace. excrepr = excinfo.exconly() else: - self.parent._prunetraceback(excinfo) + self.parent._prunetraceback(excinfo) # type: ignore[no-untyped-call] excrepr = excinfo.getrepr(style='short') return "data: {}:{}:\n{}".format(self.file, self.line, excrepr) @@ -510,7 +513,7 @@ def pytest_pycollect_makeitem(collector: Any, name: str, # Non-None result means this obj is a test case. # The collect method of the returned DataSuiteCollector instance will be called later, # with self.obj being obj. - return DataSuiteCollector.from_parent(parent=collector, name=name) + return DataSuiteCollector.from_parent(parent=collector, name=name) # type: ignore[no-untyped-call] return None @@ -550,8 +553,8 @@ def split_test_cases(parent: 'DataSuiteCollector', suite: 'DataSuite', line_no += data.count('\n') + 1 -class DataSuiteCollector(pytest.Class): # type: ignore # inheriting from Any - def collect(self) -> Iterator[pytest.Item]: # type: ignore +class DataSuiteCollector(pytest.Class): + def collect(self) -> Iterator[pytest.Item]: """Called by pytest on each of the object returned from pytest_pycollect_makeitem""" # obj is the object for which pytest_pycollect_makeitem returned self. diff --git a/mypy/test/helpers.py b/mypy/test/helpers.py index 46c01114c46c..91c5ff6ab2b4 100644 --- a/mypy/test/helpers.py +++ b/mypy/test/helpers.py @@ -10,7 +10,7 @@ from mypy import defaults import mypy.api as api -import pytest # type: ignore # no pytest in typeshed +import pytest # Exporting Suite as alias to TestCase for backwards compatibility # TODO: avoid aliasing - import and subclass TestCase directly diff --git a/mypy/test/testfinegrained.py b/mypy/test/testfinegrained.py index 596391da4474..d4ed18cab095 100644 --- a/mypy/test/testfinegrained.py +++ b/mypy/test/testfinegrained.py @@ -35,7 +35,7 @@ from mypy.config_parser import parse_config_file from mypy.find_sources import create_source_list -import pytest # type: ignore # no pytest in typeshed +import pytest # Set to True to perform (somewhat expensive) checks for duplicate AST nodes after merge CHECK_CONSISTENCY = False diff --git a/mypy/test/testipc.py b/mypy/test/testipc.py index 1d4829d56171..7dd829a59079 100644 --- a/mypy/test/testipc.py +++ b/mypy/test/testipc.py @@ -3,7 +3,7 @@ from mypy.ipc import IPCClient, IPCServer -import pytest # type: ignore +import pytest import sys import time diff --git a/mypy/test/testparse.py b/mypy/test/testparse.py index e990a403a52e..e9ff6839bc2c 100644 --- a/mypy/test/testparse.py +++ b/mypy/test/testparse.py @@ -2,7 +2,7 @@ import sys -from pytest import skip # type: ignore[import] +from pytest import skip from mypy import defaults from mypy.test.helpers import assert_string_arrays_equal, parse_options diff --git a/mypy/test/testpep561.py b/mypy/test/testpep561.py index a8eabd7702a1..aadf01ae5fa2 100644 --- a/mypy/test/testpep561.py +++ b/mypy/test/testpep561.py @@ -1,6 +1,6 @@ from contextlib import contextmanager import os -import pytest # type: ignore +import pytest import re import subprocess from subprocess import PIPE diff --git a/mypy/test/testpythoneval.py b/mypy/test/testpythoneval.py index 7586a3854eea..e7e9f1618388 100644 --- a/mypy/test/testpythoneval.py +++ b/mypy/test/testpythoneval.py @@ -18,7 +18,7 @@ import sys from tempfile import TemporaryDirectory -import pytest # type: ignore # no pytest in typeshed +import pytest from typing import List diff --git a/mypyc/test/testutil.py b/mypyc/test/testutil.py index 18ab39a103ad..c1ce8626badb 100644 --- a/mypyc/test/testutil.py +++ b/mypyc/test/testutil.py @@ -7,7 +7,7 @@ import shutil from typing import List, Callable, Iterator, Optional, Tuple -import pytest # type: ignore[import] +import pytest from mypy import build from mypy.errors import CompileError diff --git a/pytest.ini b/pytest.ini index f90d92934aba..ed76809091a1 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,6 +1,5 @@ [pytest] -# testpaths is new in 2.8 -minversion = 5.4 +minversion = 6.0.0 testpaths = mypy/test mypyc/test diff --git a/test-requirements.txt b/test-requirements.txt index fd052aaad170..79eadca595de 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -5,7 +5,7 @@ flake8-bugbear; python_version >= '3.5' flake8-pyi>=20.5; python_version >= '3.6' lxml>=4.4.0 psutil>=4.0 -pytest>=6.0.1,<7.0.0 +pytest>=6.0.0,<7.0.0 pytest-xdist>=1.34.0,<2.0.0 pytest-forked>=1.3.0,<2.0.0 pytest-cov>=2.10.0,<3.0.0 From 828d6190e4d5e1e78e8a5d3cc1f73d6f6f061c66 Mon Sep 17 00:00:00 2001 From: Lawrence Chan Date: Tue, 4 Aug 2020 16:58:08 -0500 Subject: [PATCH 5/5] Make flake8 happy --- mypy/test/data.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mypy/test/data.py b/mypy/test/data.py index 19fb8d00a818..a4f2d798b1b1 100644 --- a/mypy/test/data.py +++ b/mypy/test/data.py @@ -513,7 +513,9 @@ def pytest_pycollect_makeitem(collector: Any, name: str, # Non-None result means this obj is a test case. # The collect method of the returned DataSuiteCollector instance will be called later, # with self.obj being obj. - return DataSuiteCollector.from_parent(parent=collector, name=name) # type: ignore[no-untyped-call] + return DataSuiteCollector.from_parent( # type: ignore[no-untyped-call] + parent=collector, name=name + ) return None pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy