Skip to content

Commit 962aede

Browse files
authored
Merge pull request #3096 from nicoddemus/import-warnings
Ignore ImportWarnings regarding package resolution
2 parents a8d3d32 + b6b36bc commit 962aede

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

_pytest/python.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,17 @@
3030
from _pytest.outcomes import fail
3131
from _pytest.mark import transfer_markers
3232

33-
cutdir1 = py.path.local(pluggy.__file__.rstrip("oc"))
34-
cutdir2 = py.path.local(_pytest.__file__).dirpath()
35-
cutdir3 = py.path.local(py.__file__).dirpath()
33+
34+
# relative paths that we use to filter traceback entries from appearing to the user;
35+
# see filter_traceback
36+
# note: if we need to add more paths than what we have now we should probably use a list
37+
# for better maintenance
38+
_pluggy_dir = py.path.local(pluggy.__file__.rstrip("oc"))
39+
# pluggy is either a package or a single module depending on the version
40+
if _pluggy_dir.basename == '__init__.py':
41+
_pluggy_dir = _pluggy_dir.dirpath()
42+
_pytest_dir = py.path.local(_pytest.__file__).dirpath()
43+
_py_dir = py.path.local(py.__file__).dirpath()
3644

3745

3846
def filter_traceback(entry):
@@ -47,10 +55,10 @@ def filter_traceback(entry):
4755
is_generated = '<' in raw_filename and '>' in raw_filename
4856
if is_generated:
4957
return False
50-
# entry.path might point to an inexisting file, in which case it will
51-
# alsso return a str object. see #1133
58+
# entry.path might point to an non-existing file, in which case it will
59+
# also return a str object. see #1133
5260
p = py.path.local(entry.path)
53-
return p != cutdir1 and not p.relto(cutdir2) and not p.relto(cutdir3)
61+
return not p.relto(_pluggy_dir) and not p.relto(_pytest_dir) and not p.relto(_py_dir)
5462

5563

5664
def pyobj_property(name):
@@ -563,7 +571,6 @@ def _prunetraceback(self, excinfo):
563571
if ntraceback == traceback:
564572
ntraceback = ntraceback.cut(path=path)
565573
if ntraceback == traceback:
566-
# ntraceback = ntraceback.cut(excludepath=cutdir2)
567574
ntraceback = ntraceback.filter(filter_traceback)
568575
if not ntraceback:
569576
ntraceback = traceback

tox.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ filterwarnings =
215215
ignore:.*type argument to addoption.*:DeprecationWarning
216216
# produced by python >=3.5 on execnet (pytest-xdist)
217217
ignore:.*inspect.getargspec.*deprecated, use inspect.signature.*:DeprecationWarning
218+
# ignore warning about package resolution using __spec__ or __package__
219+
# should be a temporary solution, see #3061 for discussion
220+
ignore:.*can't resolve package from __spec__ or __package__.*:ImportWarning
218221
219222
[flake8]
220223
max-line-length = 120

0 commit comments

Comments
 (0)