Merge pull request #3096 from nicoddemus/import-warnings

Ignore ImportWarnings regarding package resolution
This commit is contained in:
Bruno Oliveira 2018-01-09 18:40:33 -02:00 committed by GitHub
commit 962aede290
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 7 deletions

View File

@ -30,9 +30,17 @@ from _pytest.compat import (
from _pytest.outcomes import fail from _pytest.outcomes import fail
from _pytest.mark import transfer_markers from _pytest.mark import transfer_markers
cutdir1 = py.path.local(pluggy.__file__.rstrip("oc"))
cutdir2 = py.path.local(_pytest.__file__).dirpath() # relative paths that we use to filter traceback entries from appearing to the user;
cutdir3 = py.path.local(py.__file__).dirpath() # see filter_traceback
# note: if we need to add more paths than what we have now we should probably use a list
# for better maintenance
_pluggy_dir = py.path.local(pluggy.__file__.rstrip("oc"))
# pluggy is either a package or a single module depending on the version
if _pluggy_dir.basename == '__init__.py':
_pluggy_dir = _pluggy_dir.dirpath()
_pytest_dir = py.path.local(_pytest.__file__).dirpath()
_py_dir = py.path.local(py.__file__).dirpath()
def filter_traceback(entry): def filter_traceback(entry):
@ -47,10 +55,10 @@ def filter_traceback(entry):
is_generated = '<' in raw_filename and '>' in raw_filename is_generated = '<' in raw_filename and '>' in raw_filename
if is_generated: if is_generated:
return False return False
# entry.path might point to an inexisting file, in which case it will # entry.path might point to an non-existing file, in which case it will
# alsso return a str object. see #1133 # also return a str object. see #1133
p = py.path.local(entry.path) p = py.path.local(entry.path)
return p != cutdir1 and not p.relto(cutdir2) and not p.relto(cutdir3) return not p.relto(_pluggy_dir) and not p.relto(_pytest_dir) and not p.relto(_py_dir)
def pyobj_property(name): def pyobj_property(name):
@ -563,7 +571,6 @@ class FunctionMixin(PyobjMixin):
if ntraceback == traceback: if ntraceback == traceback:
ntraceback = ntraceback.cut(path=path) ntraceback = ntraceback.cut(path=path)
if ntraceback == traceback: if ntraceback == traceback:
# ntraceback = ntraceback.cut(excludepath=cutdir2)
ntraceback = ntraceback.filter(filter_traceback) ntraceback = ntraceback.filter(filter_traceback)
if not ntraceback: if not ntraceback:
ntraceback = traceback ntraceback = traceback

View File

@ -215,6 +215,9 @@ filterwarnings =
ignore:.*type argument to addoption.*:DeprecationWarning ignore:.*type argument to addoption.*:DeprecationWarning
# produced by python >=3.5 on execnet (pytest-xdist) # produced by python >=3.5 on execnet (pytest-xdist)
ignore:.*inspect.getargspec.*deprecated, use inspect.signature.*:DeprecationWarning ignore:.*inspect.getargspec.*deprecated, use inspect.signature.*:DeprecationWarning
# ignore warning about package resolution using __spec__ or __package__
# should be a temporary solution, see #3061 for discussion
ignore:.*can't resolve package from __spec__ or __package__.*:ImportWarning
[flake8] [flake8]
max-line-length = 120 max-line-length = 120