MCPcopy
hub / github.com/pytest-dev/pytest / test_importplugin_error_message

Function test_importplugin_error_message

testing/test_pluginmanager.py:238–260  ·  view source on GitHub ↗

Don't hide import errors when importing plugins and provide an easy to debug message. See #375 and #1998.

(
    pytester: Pytester, pytestpm: PytestPluginManager
)

Source from the content-addressed store, hash-verified

236
237
238def test_importplugin_error_message(
239 pytester: Pytester, pytestpm: PytestPluginManager
240) -> None:
241 """Don't hide import errors when importing plugins and provide
242 an easy to debug message.
243
244 See #375 and #1998.
245 """
246 pytester.syspathinsert(pytester.path)
247 pytester.makepyfile(
248 qwe="""\
249 def test_traceback():
250 raise ImportError('Not possible to import: ☺')
251 test_traceback()
252 """
253 )
254 with pytest.raises(ImportError) as excinfo:
255 pytestpm.import_plugin("qwe")
256
257 assert str(excinfo.value).endswith(
258 'Error importing plugin "qwe": Not possible to import: ☺'
259 )
260 assert "in test_traceback" in str(excinfo.traceback[-1])
261
262
263class TestPytestPluginManager:

Callers

nothing calls this directly

Calls 4

import_pluginMethod · 0.80
endswithMethod · 0.80
syspathinsertMethod · 0.45
makepyfileMethod · 0.45

Tested by

no test coverage detected