Skip to content

Commit 1d66e7a

Browse files
neozenithdmtucker
authored andcommitted
Add a configurable name to MypyItem node IDs
1 parent 75433de commit 1d66e7a

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/pytest_mypy.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111

1212
mypy_argv = []
13+
nodeid_name = 'mypy'
1314

1415

1516
def pytest_addoption(parser):
@@ -77,7 +78,14 @@ def pytest_collect_file(path, parent):
7778
parent.config.option.mypy,
7879
parent.config.option.mypy_ignore_missing_imports,
7980
]):
80-
return MypyItem(path, parent)
81+
item = MypyItem(path, parent)
82+
if nodeid_name:
83+
item = MypyItem(
84+
path,
85+
parent,
86+
nodeid='::'.join([item.nodeid, nodeid_name]),
87+
)
88+
return item
8189
return None
8290

8391

tests/test_pytest_mypy.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,19 @@ def pytest_configure(config):
145145
assert result.ret == 0
146146

147147

148+
def test_api_nodeid_name(testdir, xdist_args):
149+
"""Ensure that the plugin can be configured in a conftest.py."""
150+
nodeid_name = 'UnmistakableNodeIDName'
151+
testdir.makepyfile(conftest='''
152+
def pytest_configure(config):
153+
plugin = config.pluginmanager.getplugin('mypy')
154+
plugin.nodeid_name = '{}'
155+
'''.format(nodeid_name))
156+
result = testdir.runpytest_subprocess('--mypy', '--verbose', *xdist_args)
157+
result.stdout.fnmatch_lines(['*conftest.py::' + nodeid_name + '*'])
158+
assert result.ret == 0
159+
160+
148161
def test_pytest_collection_modifyitems(testdir, xdist_args):
149162
testdir.makepyfile(conftest='''
150163
def pytest_collection_modifyitems(session, config, items):

0 commit comments

Comments
 (0)