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

please don't suppress tracebacks on ImportError during test collection #1976

cwitty opened this Issue Oct 2, 2016 · 3 comments


None yet
3 participants

cwitty commented Oct 2, 2016

This chunk of code in _pytest/ (from pytest-3.0.3):

    except ImportError:
        exc_class, exc, _ = sys.exc_info()
        raise self.CollectError(
            "ImportError while importing test module '%s'.\n"
            "Original error message:\n'%s'\n"
            "Make sure your test modules/packages have valid Python names."
            % (self.fspath, exc or exc_class)

ignores the traceback. Please print at least the line and file number of the original failing import.

(I was just refactoring my code, and moved some code around in a way that I knew would cause import errors. But I don't know everywhere this code is imported from, without searching my whole code base or letting my test suite tell me. And if my test suite won't tell me more than "it's broken", then I'm back to searching the code base.)

Minimal example:

(venv) cwitty@helix:/tmp/pttest$ touch
(venv) cwitty@helix:/tmp/pttest$ echo 'from a import anything' >
(venv) cwitty@helix:/tmp/pttest$ echo 'import b' >
(venv) cwitty@helix:/tmp/pttest$ pytest

with result:

_________________________ ERROR collecting __________________________
ImportError while importing test module '/tmp/pttest/'.
Original error message:
'cannot import name 'anything''
Make sure your test modules/packages have valid Python names.

Note that the error message doesn't even mention, the file with the problem.


This comment has been minimized.


nicoddemus commented Oct 2, 2016

I agree, I've found the need for this myself on accasion.

nicoddemus added a commit to nicoddemus/pytest that referenced this issue Oct 4, 2016

Display traceback from Import errors using pytest's short representation
Also omit pytest's own modules and internal libraries (py and pluggy) in low verbosity

Fix pytest-dev#1976

This comment has been minimized.

cwitty commented Oct 4, 2016

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment