Skip to content

Commit 3eb8071

Browse files
committed
Use pytest Node.from_parent if available
1 parent ffd9d1c commit 3eb8071

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

mypy/test/data.py

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,18 @@
1010
import sys
1111

1212
import pytest # type: ignore # no pytest in typeshed
13-
from typing import List, Tuple, Set, Optional, Iterator, Any, Dict, NamedTuple, Union
13+
from typing import (
14+
Any,
15+
Callable,
16+
Dict,
17+
Iterator,
18+
List,
19+
NamedTuple,
20+
Optional,
21+
Set,
22+
Tuple,
23+
Union,
24+
)
1425

1526
from mypy.test.config import test_data_prefix, test_temp_dir, PREFIX
1627

@@ -510,7 +521,10 @@ def pytest_pycollect_makeitem(collector: Any, name: str,
510521
# Non-None result means this obj is a test case.
511522
# The collect method of the returned DataSuiteCollector instance will be called later,
512523
# with self.obj being obj.
513-
return DataSuiteCollector(name, parent=collector)
524+
if hasattr(DataSuiteCollector, 'from_parent'):
525+
return DataSuiteCollector.from_parent(parent=collector, name=name)
526+
else:
527+
return DataSuiteCollector(name=name, parent=collector)
514528
return None
515529

516530

@@ -535,14 +549,22 @@ def split_test_cases(parent: 'DataSuiteCollector', suite: 'DataSuite',
535549
for i in range(1, len(cases), 6):
536550
name, writescache, only_when, platform_flag, skip, data = cases[i:i + 6]
537551
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)
552+
if hasattr(DataDrivenTestCase, 'from_parent'):
553+
creator: Callable[..., DataDrivenTestCase] = DataDrivenTestCase.from_parent
554+
else:
555+
creator = DataDrivenTestCase
556+
yield creator(
557+
parent=parent,
558+
suite=suite,
559+
file=file,
560+
name=add_test_name_suffix(name, suite.test_name_suffix),
561+
writescache=bool(writescache),
562+
only_when=only_when,
563+
platform=platform,
564+
skip=bool(skip),
565+
data=data,
566+
line=line_no,
567+
)
546568
line_no += data.count('\n') + 1
547569

548570

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