Improve error message when a plugin fails to import
This commit is contained in:
parent
6d4b14d7ee
commit
7a186df271
|
@ -5,6 +5,11 @@
|
||||||
|
|
||||||
*
|
*
|
||||||
|
|
||||||
|
*
|
||||||
|
|
||||||
|
* Improve error message when a plugin fails to load.
|
||||||
|
Thanks `@nicoddemus`_ for the PR.
|
||||||
|
|
||||||
* Fix (`#1178 <https://github.com/pytest-dev/pytest/issues/1178>`_):
|
* Fix (`#1178 <https://github.com/pytest-dev/pytest/issues/1178>`_):
|
||||||
``pytest.fail`` with non-ascii characters raises an internal pytest error.
|
``pytest.fail`` with non-ascii characters raises an internal pytest error.
|
||||||
Thanks `@nicoddemus`_ for the PR.
|
Thanks `@nicoddemus`_ for the PR.
|
||||||
|
@ -12,7 +17,6 @@
|
||||||
* Fix (`#469`_): junit parses report.nodeid incorrectly, when params IDs
|
* Fix (`#469`_): junit parses report.nodeid incorrectly, when params IDs
|
||||||
contain ``::``. Thanks `@tomviner`_ for the PR (`#1431`_).
|
contain ``::``. Thanks `@tomviner`_ for the PR (`#1431`_).
|
||||||
|
|
||||||
|
|
||||||
* Fix (`#578 <https://github.com/pytest-dev/pytest/issues/578>`_): SyntaxErrors
|
* Fix (`#578 <https://github.com/pytest-dev/pytest/issues/578>`_): SyntaxErrors
|
||||||
containing non-ascii lines at the point of failure generated an internal
|
containing non-ascii lines at the point of failure generated an internal
|
||||||
py.test error.
|
py.test error.
|
||||||
|
@ -23,6 +27,8 @@
|
||||||
|
|
||||||
*
|
*
|
||||||
|
|
||||||
|
*
|
||||||
|
|
||||||
|
|
||||||
.. _#1437: https://github.com/pytest-dev/pytest/issues/1437
|
.. _#1437: https://github.com/pytest-dev/pytest/issues/1437
|
||||||
.. _#469: https://github.com/pytest-dev/pytest/issues/469
|
.. _#469: https://github.com/pytest-dev/pytest/issues/469
|
||||||
|
|
|
@ -383,8 +383,8 @@ class PytestPluginManager(PluginManager):
|
||||||
importspec = modname
|
importspec = modname
|
||||||
try:
|
try:
|
||||||
__import__(importspec)
|
__import__(importspec)
|
||||||
except ImportError:
|
except ImportError as e:
|
||||||
raise
|
raise ImportError('Error importing plugin "%s": %s' % (modname, e))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
import pytest
|
import pytest
|
||||||
if not hasattr(pytest, 'skip') or not isinstance(e, pytest.skip.Exception):
|
if not hasattr(pytest, 'skip') or not isinstance(e, pytest.skip.Exception):
|
||||||
|
|
|
@ -178,13 +178,17 @@ def test_default_markers(testdir):
|
||||||
"*trylast*last*",
|
"*trylast*last*",
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
def test_importplugin_issue375(testdir, pytestpm):
|
def test_importplugin_issue375(testdir, pytestpm):
|
||||||
|
"""Don't hide import errors when importing plugins and provide
|
||||||
|
an easy to debug message.
|
||||||
|
"""
|
||||||
testdir.syspathinsert(testdir.tmpdir)
|
testdir.syspathinsert(testdir.tmpdir)
|
||||||
testdir.makepyfile(qwe="import aaaa")
|
testdir.makepyfile(qwe="import aaaa")
|
||||||
with pytest.raises(ImportError) as excinfo:
|
with pytest.raises(ImportError) as excinfo:
|
||||||
pytestpm.import_plugin("qwe")
|
pytestpm.import_plugin("qwe")
|
||||||
assert "qwe" not in str(excinfo.value)
|
expected = '.*Error importing plugin "qwe": No module named \'?aaaa\'?'
|
||||||
assert "aaaa" in str(excinfo.value)
|
assert py.std.re.match(expected, str(excinfo.value))
|
||||||
|
|
||||||
|
|
||||||
class TestPytestPluginManager:
|
class TestPytestPluginManager:
|
||||||
|
|
Loading…
Reference in New Issue