Don't hide import errors when importing plugins and provide an easy to debug message. See #375 and #1998.
(
pytester: Pytester, pytestpm: PytestPluginManager
)
| 188 | |
| 189 | |
| 190 | def test_importplugin_error_message( |
| 191 | pytester: Pytester, pytestpm: PytestPluginManager |
| 192 | ) -> None: |
| 193 | """Don't hide import errors when importing plugins and provide |
| 194 | an easy to debug message. |
| 195 | |
| 196 | See #375 and #1998. |
| 197 | """ |
| 198 | pytester.syspathinsert(pytester.path) |
| 199 | pytester.makepyfile( |
| 200 | qwe="""\ |
| 201 | def test_traceback(): |
| 202 | raise ImportError('Not possible to import: ☺') |
| 203 | test_traceback() |
| 204 | """ |
| 205 | ) |
| 206 | with pytest.raises(ImportError) as excinfo: |
| 207 | pytestpm.import_plugin("qwe") |
| 208 | |
| 209 | assert str(excinfo.value).endswith( |
| 210 | 'Error importing plugin "qwe": Not possible to import: ☺' |
| 211 | ) |
| 212 | assert "in test_traceback" in str(excinfo.traceback[-1]) |
| 213 | |
| 214 | |
| 215 | class TestPytestPluginManager: |
nothing calls this directly
no test coverage detected