Skip to content

Commit 3e77959

Browse files
authored
Use pytest Node.from_parent if available (python#9263)
* Use pytest Node.from_parent if available * Use pytest Node.from_parent unconditionally (requires pytest 5.4+) * Bump pytest test requirements * Require pytest 6.0 and remove unused type ignores * Make flake8 happy
1 parent ffd9d1c commit 3e77959

File tree

10 files changed

+35
-28
lines changed

10 files changed

+35
-28
lines changed

mypy/test/data.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from abc import abstractmethod
1010
import sys
1111

12-
import pytest # type: ignore # no pytest in typeshed
12+
import pytest
1313
from typing import List, Tuple, Set, Optional, Iterator, Any, Dict, NamedTuple, Union
1414

1515
from mypy.test.config import test_data_prefix, test_temp_dir, PREFIX
@@ -160,9 +160,12 @@ def parse_test_case(case: 'DataDrivenTestCase') -> None:
160160
case.expected_fine_grained_targets = targets
161161

162162

163-
class DataDrivenTestCase(pytest.Item): # type: ignore # inheriting from Any
163+
class DataDrivenTestCase(pytest.Item):
164164
"""Holds parsed data-driven test cases, and handles directory setup and teardown."""
165165

166+
# Override parent member type
167+
parent = None # type: DataSuiteCollector
168+
166169
input = None # type: List[str]
167170
output = None # type: List[str] # Output for the first pass
168171
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:
266269
# call exit() and they already print out a stack trace.
267270
excrepr = excinfo.exconly()
268271
else:
269-
self.parent._prunetraceback(excinfo)
272+
self.parent._prunetraceback(excinfo) # type: ignore[no-untyped-call]
270273
excrepr = excinfo.getrepr(style='short')
271274

272275
return "data: {}:{}:\n{}".format(self.file, self.line, excrepr)
@@ -510,7 +513,9 @@ def pytest_pycollect_makeitem(collector: Any, name: str,
510513
# Non-None result means this obj is a test case.
511514
# The collect method of the returned DataSuiteCollector instance will be called later,
512515
# with self.obj being obj.
513-
return DataSuiteCollector(name, parent=collector)
516+
return DataSuiteCollector.from_parent( # type: ignore[no-untyped-call]
517+
parent=collector, name=name
518+
)
514519
return None
515520

516521

@@ -535,19 +540,23 @@ def split_test_cases(parent: 'DataSuiteCollector', suite: 'DataSuite',
535540
for i in range(1, len(cases), 6):
536541
name, writescache, only_when, platform_flag, skip, data = cases[i:i + 6]
537542
platform = platform_flag[1:] if platform_flag else None
538-
yield DataDrivenTestCase(parent, suite, file,
539-
name=add_test_name_suffix(name, suite.test_name_suffix),
540-
writescache=bool(writescache),
541-
only_when=only_when,
542-
platform=platform,
543-
skip=bool(skip),
544-
data=data,
545-
line=line_no)
543+
yield DataDrivenTestCase.from_parent(
544+
parent=parent,
545+
suite=suite,
546+
file=file,
547+
name=add_test_name_suffix(name, suite.test_name_suffix),
548+
writescache=bool(writescache),
549+
only_when=only_when,
550+
platform=platform,
551+
skip=bool(skip),
552+
data=data,
553+
line=line_no,
554+
)
546555
line_no += data.count('\n') + 1
547556

548557

549-
class DataSuiteCollector(pytest.Class): # type: ignore # inheriting from Any
550-
def collect(self) -> Iterator[pytest.Item]: # type: ignore
558+
class DataSuiteCollector(pytest.Class):
559+
def collect(self) -> Iterator[pytest.Item]:
551560
"""Called by pytest on each of the object returned from pytest_pycollect_makeitem"""
552561

553562
# obj is the object for which pytest_pycollect_makeitem returned self.

mypy/test/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from mypy import defaults
1111
import mypy.api as api
1212

13-
import pytest # type: ignore # no pytest in typeshed
13+
import pytest
1414

1515
# Exporting Suite as alias to TestCase for backwards compatibility
1616
# TODO: avoid aliasing - import and subclass TestCase directly

mypy/test/testfinegrained.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from mypy.config_parser import parse_config_file
3636
from mypy.find_sources import create_source_list
3737

38-
import pytest # type: ignore # no pytest in typeshed
38+
import pytest
3939

4040
# Set to True to perform (somewhat expensive) checks for duplicate AST nodes after merge
4141
CHECK_CONSISTENCY = False

mypy/test/testipc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from mypy.ipc import IPCClient, IPCServer
55

6-
import pytest # type: ignore
6+
import pytest
77
import sys
88
import time
99

mypy/test/testparse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import sys
44

5-
from pytest import skip # type: ignore[import]
5+
from pytest import skip
66

77
from mypy import defaults
88
from mypy.test.helpers import assert_string_arrays_equal, parse_options

mypy/test/testpep561.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from contextlib import contextmanager
22
import os
3-
import pytest # type: ignore
3+
import pytest
44
import re
55
import subprocess
66
from subprocess import PIPE

mypy/test/testpythoneval.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import sys
1919
from tempfile import TemporaryDirectory
2020

21-
import pytest # type: ignore # no pytest in typeshed
21+
import pytest
2222

2323
from typing import List
2424

mypyc/test/testutil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import shutil
88
from typing import List, Callable, Iterator, Optional, Tuple
99

10-
import pytest # type: ignore[import]
10+
import pytest
1111

1212
from mypy import build
1313
from mypy.errors import CompileError

pytest.ini

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[pytest]
2-
# testpaths is new in 2.8
3-
minversion = 2.8
2+
minversion = 6.0.0
43

54
testpaths = mypy/test mypyc/test
65

test-requirements.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ flake8-bugbear; python_version >= '3.5'
55
flake8-pyi>=20.5; python_version >= '3.6'
66
lxml>=4.4.0
77
psutil>=4.0
8-
pytest==5.3.2
9-
pytest-xdist>=1.22
10-
# pytest-xdist depends on pytest-forked and 1.1.0 doesn't install clean on macOS 3.5
11-
pytest-forked>=1.0.0,<1.1.0
12-
pytest-cov>=2.4.0
8+
pytest>=6.0.0,<7.0.0
9+
pytest-xdist>=1.34.0,<2.0.0
10+
pytest-forked>=1.3.0,<2.0.0
11+
pytest-cov>=2.10.0,<3.0.0
1312
typing>=3.5.2; python_version < '3.5'
1413
py>=1.5.2
1514
virtualenv<20

0 commit comments

Comments
 (0)
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