From 3dd24f8d218408f421aa9c88b7343bbb54e423f8 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Mon, 8 Jan 2018 20:32:45 -0200 Subject: [PATCH 1/2] Ignore ImportWarnings regarding package resolution The problem is described/discussed in #3061 Ideally this should be a temporary solution until we find a proper one which gets rid of the warning --- tox.ini | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tox.ini b/tox.ini index 38ebaf69f..32996626a 100644 --- a/tox.ini +++ b/tox.ini @@ -215,6 +215,9 @@ filterwarnings = ignore:.*type argument to addoption.*:DeprecationWarning # produced by python >=3.5 on execnet (pytest-xdist) 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] max-line-length = 120 From b6b36bc167b1d05b9b8353e38e2cedd124d1f4e1 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Mon, 8 Jan 2018 21:27:53 -0200 Subject: [PATCH 2/2] Handle pluggy package or module for traceback filtering Since 0.6.1 pluggy has been turned into a package --- _pytest/python.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/_pytest/python.py b/_pytest/python.py index 650171a9e..3940028fa 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -30,9 +30,17 @@ from _pytest.compat import ( from _pytest.outcomes import fail from _pytest.mark import transfer_markers -cutdir1 = py.path.local(pluggy.__file__.rstrip("oc")) -cutdir2 = py.path.local(_pytest.__file__).dirpath() -cutdir3 = py.path.local(py.__file__).dirpath() + +# relative paths that we use to filter traceback entries from appearing to the user; +# 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): @@ -47,10 +55,10 @@ def filter_traceback(entry): is_generated = '<' in raw_filename and '>' in raw_filename if is_generated: return False - # entry.path might point to an inexisting file, in which case it will - # alsso return a str object. see #1133 + # entry.path might point to an non-existing file, in which case it will + # also return a str object. see #1133 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): @@ -563,7 +571,6 @@ class FunctionMixin(PyobjMixin): if ntraceback == traceback: ntraceback = ntraceback.cut(path=path) if ntraceback == traceback: - # ntraceback = ntraceback.cut(excludepath=cutdir2) ntraceback = ntraceback.filter(filter_traceback) if not ntraceback: ntraceback = traceback