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

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

Closed
cwitty opened this issue Oct 2, 2016 · 3 comments
Closed
Labels
good first issue easy issue that is friendly to new contributor type: enhancement new feature or API change, should be merged into features branch

Comments

@cwitty
Copy link

cwitty commented Oct 2, 2016

This chunk of code in _pytest/python.py (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 a.py
(venv) cwitty@helix:/tmp/pttest$ echo 'from a import anything' > b.py
(venv) cwitty@helix:/tmp/pttest$ echo 'import b' > test_b.py
(venv) cwitty@helix:/tmp/pttest$ pytest

with result:

_________________________ ERROR collecting test_b.py __________________________
ImportError while importing test module '/tmp/pttest/test_b.py'.
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 b.py, the file with the problem.

@nicoddemus nicoddemus added type: enhancement new feature or API change, should be merged into features branch good first issue easy issue that is friendly to new contributor labels Oct 2, 2016
@nicoddemus
Copy link
Member

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
Also omit pytest's own modules and internal libraries (py and pluggy) in low verbosity

Fix pytest-dev#1976
@cwitty
Copy link
Author

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
Labels
good first issue easy issue that is friendly to new contributor type: enhancement new feature or API change, should be merged into features branch
Projects
None yet
Development

No branches or pull requests

3 participants