Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import_plugin hides exception source #2491

Closed
RonnyPfannschmidt opened this issue Jun 11, 2017 · 10 comments
Closed

import_plugin hides exception source #2491

RonnyPfannschmidt opened this issue Jun 11, 2017 · 10 comments
Labels
type: bug problem that needs to be addressed type: infrastructure improvement to development/releases/CI structure

Comments

@RonnyPfannschmidt
Copy link
Member

Traceback (most recent call last):
  File "/home/rpfannsc/Projects/pytest-dev/pytest-venv/bin/pytest", line 11, in <module>
    load_entry_point('pytest', 'console_scripts', 'pytest')()
  File "/home/rpfannsc/Projects/pytest-dev/pytest-venv/lib/python3.5/site-packages/pkg_resources/__init__.py", line 560, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/home/rpfannsc/Projects/pytest-dev/pytest-venv/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2648, in load_entry_point
    return ep.load()
  File "/home/rpfannsc/Projects/pytest-dev/pytest-venv/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2302, in load
    return self.resolve()
  File "/home/rpfannsc/Projects/pytest-dev/pytest-venv/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2308, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/home/rpfannsc/Projects/pytest-dev/pytest/pytest.py", line 76, in <module>
    _preloadplugins()  # to populate pytest.* namespace so help(pytest) works
  File "/home/rpfannsc/Projects/pytest-dev/pytest/_pytest/config.py", line 117, in _preloadplugins
    _preinit.append(get_config())
  File "/home/rpfannsc/Projects/pytest-dev/pytest/_pytest/config.py", line 126, in get_config
    pluginmanager.import_plugin(spec)
  File "/home/rpfannsc/Projects/pytest-dev/pytest/_pytest/config.py", line 444, in import_plugin
    raise new_exc
ImportError: Error importing plugin "unittest": cannot import name 'fail'

as an example

its not that helpful to get the traceback cut at a bad location

@RonnyPfannschmidt RonnyPfannschmidt added type: bug problem that needs to be addressed type: infrastructure improvement to development/releases/CI structure labels Jun 11, 2017
@srinivasreddy
Copy link
Contributor

I am taking it. Or somebody working on this?

@nicoddemus
Copy link
Member

Not that I know of, please go ahead! 👍

@srinivasreddy
Copy link
Contributor

@RonnyPfannschmidt Could you please let me know what kind of stack-trace you are expecting?

@RonnyPfannschmidt
Copy link
Member Author

@srinivasreddy anything that includes the origin of the error, python3 does this nicely on its own when correclty chaining exceptions,
i wonder if a decraded mode for python3 is justifiable due to unreasonable hardship

@nicoddemus
Copy link
Member

Now that we use six, does six.reraise provides better results I wonder?

@RonnyPfannschmidt
Copy link
Member Author

@nicoddemus it cant magically enhance python2 as far as i understood

@nicoddemus
Copy link
Member

I was thinking of something like this:

import six, sys


def load_myplugin():
    from unittest import fail

def load_all_plugins():
    try:
        load_myplugin()
    except Exception as e:
        if six.PY2:
            six.reraise(type(e), type(e)('While loading plugin "myplugin":' + '\n' + str(e)), sys.exc_info()[2])
        else:
            raise type(e)('While loading plugin myplugin')

load_all_plugins()

Python 2:

Traceback (most recent call last):
  File "foo.py", line 16, in <module>
    load_all_plugins()
  File "foo.py", line 12, in load_all_plugins
    six.reraise(type(e), type(e)('While loading plugin "myplugin":' + '\n' + str(e)), sys.exc_info()[2])
  File "foo.py", line 9, in load_all_plugins
    load_myplugin()
  File "foo.py", line 5, in load_myplugin
    from unittest import fail
ImportError: While loading plugin "myplugin":
cannot import name fail

Python 3:

Traceback (most recent call last):
  File "foo.py", line 9, in load_all_plugins
    load_myplugin()
  File "foo.py", line 5, in load_myplugin
    from unittest import fail
ImportError: cannot import name 'fail'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "foo.py", line 16, in <module>
    load_all_plugins()
  File "foo.py", line 14, in load_all_plugins
    raise type(e)('While loading plugin myplugin')
ImportError: While loading plugin myplugin

@RonnyPfannschmidt
Copy link
Member Author

@nicoddemus those combinations look good

@OfirOshir
Copy link
Contributor

I created a pr to solve this issue can someone plz check it?
#2762

RonnyPfannschmidt added a commit that referenced this issue Oct 25, 2017
@nicoddemus
Copy link
Member

Fixed by #2791

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug problem that needs to be addressed type: infrastructure improvement to development/releases/CI structure
Projects
None yet
Development

No branches or pull requests

4 participants