Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 591a98c

Browse files
gnpricegvanrossum
authored andcommitted
pytest: Add some comments to explain pytest's magic (#3034)
1 parent 428a536 commit 591a98c

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

mypy/test/data.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,13 +437,17 @@ def fix_cobertura_filename(line: str) -> str:
437437
##
438438

439439

440+
# This function name is special to pytest. See
441+
# http://doc.pytest.org/en/latest/writing_plugins.html#initialization-command-line-and-configuration-hooks
440442
def pytest_addoption(parser: Any) -> None:
441443
group = parser.getgroup('mypy')
442444
group.addoption('--update-data', action='store_true', default=False,
443445
help='Update test data to reflect actual output'
444446
' (supported only for certain tests)')
445447

446448

449+
# This function name is special to pytest. See
450+
# http://doc.pytest.org/en/latest/writing_plugins.html#collection-hooks
447451
def pytest_pycollect_makeitem(collector: Any, name: str, obj: Any) -> Any:
448452
if not isinstance(obj, type) or not issubclass(obj, DataSuite):
449453
return None

pytest.ini

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ testpaths = mypy/test
66

77
python_files = test*.py
88

9-
# empty patterns for default python collector, to stick to our plugin's collector
9+
# Where do the test cases come from? We provide our own collection
10+
# logic by implementing `pytest_pycollect_makeitem` in mypy.test.data;
11+
# the test files import that module, and pytest sees the magic name
12+
# and invokes it at the relevant moment. See
13+
# http://doc.pytest.org/en/latest/writing_plugins.html#collection-hooks
14+
15+
# Because we provide our own collection logic, disable the default
16+
# python collector by giving it empty patterns to search for.
1017
python_classes =
1118
python_functions =
1219

0 commit comments

Comments
 (0)