summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorBruno Oliveira <nicoddemus@gmail.com>2016-10-03 21:46:44 -0300
committerBruno Oliveira <nicoddemus@gmail.com>2016-10-03 21:46:44 -0300
commita1d446b8e809f1e6488ce183ace93ab6693f827c (patch)
tree56f5653d5e6b9531257feac0e87089b2191f508b /testing
parent7d66e4eae1cc5989df07e140f2ff6949416c2c18 (diff)
downloadpytest-a1d446b8e809f1e6488ce183ace93ab6693f827c.tar.gz
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 #1976
Diffstat (limited to 'testing')
-rw-r--r--testing/python/collect.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/testing/python/collect.py b/testing/python/collect.py
index 04ce53a54..2913b11a4 100644
--- a/testing/python/collect.py
+++ b/testing/python/collect.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
+import os
import sys
from textwrap import dedent
@@ -71,8 +72,12 @@ class TestModule:
"Hint: make sure your test modules/packages have valid Python names.",
])
- def test_show_full_traceback_import_error(self, testdir):
- """Import errors when collecting modules should display the full traceback (#1976)."""
+ @pytest.mark.parametrize('verbose', [0, 1, 2])
+ def test_show_traceback_import_error(self, testdir, verbose):
+ """Import errors when collecting modules should display the traceback (#1976).
+
+ With low verbosity we omit pytest and internal modules, otherwise show all traceback entries.
+ """
testdir.makepyfile(
foo_traceback_import_error="""
from bar_traceback_import_error import NOT_AVAILABLE
@@ -82,15 +87,23 @@ class TestModule:
testdir.makepyfile("""
import foo_traceback_import_error
""")
- result = testdir.runpytest()
+ args = ('-v',) * verbose
+ result = testdir.runpytest(*args)
result.stdout.fnmatch_lines([
"ImportError while importing test module*",
- "Original traceback:",
+ "Traceback:",
"*from bar_traceback_import_error import NOT_AVAILABLE",
"*cannot import name *NOT_AVAILABLE*",
])
assert result.ret == 2
+ stdout = result.stdout.str()
+ for name in ('_pytest', os.path.join('py', '_path')):
+ if verbose == 2:
+ assert name in stdout
+ else:
+ assert name not in stdout
+
class TestClass:
def test_class_with_init_warning(self, testdir):