Skip to content

Commit

Permalink
Add a configurable name to MypyItem node IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
neozenith authored and dmtucker committed Feb 14, 2020
1 parent 75433de commit 1d66e7a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/pytest_mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


mypy_argv = []
nodeid_name = 'mypy'


def pytest_addoption(parser):
Expand Down Expand Up @@ -77,7 +78,14 @@ def pytest_collect_file(path, parent):
parent.config.option.mypy,
parent.config.option.mypy_ignore_missing_imports,
]):
return MypyItem(path, parent)
item = MypyItem(path, parent)
if nodeid_name:
item = MypyItem(
path,
parent,
nodeid='::'.join([item.nodeid, nodeid_name]),
)
return item
return None


Expand Down
13 changes: 13 additions & 0 deletions tests/test_pytest_mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,19 @@ def pytest_configure(config):
assert result.ret == 0


def test_api_nodeid_name(testdir, xdist_args):
"""Ensure that the plugin can be configured in a conftest.py."""
nodeid_name = 'UnmistakableNodeIDName'
testdir.makepyfile(conftest='''
def pytest_configure(config):
plugin = config.pluginmanager.getplugin('mypy')
plugin.nodeid_name = '{}'
'''.format(nodeid_name))
result = testdir.runpytest_subprocess('--mypy', '--verbose', *xdist_args)
result.stdout.fnmatch_lines(['*conftest.py::' + nodeid_name + '*'])
assert result.ret == 0


def test_pytest_collection_modifyitems(testdir, xdist_args):
testdir.makepyfile(conftest='''
def pytest_collection_modifyitems(session, config, items):
Expand Down

0 comments on commit 1d66e7a

Please sign in to comment.