From 2c730743f1b80b38b044ecc08c98609df60ba375 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 21 Mar 2017 22:17:07 -0300 Subject: [PATCH] Fix errors related to warnings raised by xdist - pytester was creating a 'pexpect' directory to serve as temporary dir, but due to the fact that xdist adds the current directory to sys.path, that directory was being considered as candidate for import as a package. The directory is empty and a warning was being raised about it missing __init__ file, which is now turned into an error by our filterwarnings config in pytest.ini. - Decided to play it safe and ignore any warnings during `pytest.importorskip`. - pytest-xdist and execnet raise two warnings which should be fixed upstream: pytest-dev/pytest-xdist/issues/133 --- _pytest/pytester.py | 2 +- _pytest/runner.py | 17 ++++++++++++----- tox.ini | 4 ++++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/_pytest/pytester.py b/_pytest/pytester.py index ee0e5bbe7..6381595ee 100644 --- a/_pytest/pytester.py +++ b/_pytest/pytester.py @@ -1008,7 +1008,7 @@ class Testdir(object): The pexpect child is returned. """ - basetemp = self.tmpdir.mkdir("pexpect") + basetemp = self.tmpdir.mkdir("temp-pexpect") invoke = " ".join(map(str, self._getpytestargs())) cmd = "%s --basetemp=%s %s" % (invoke, basetemp, string) return self.spawn(cmd, expect_timeout=expect_timeout) diff --git a/_pytest/runner.py b/_pytest/runner.py index 4277f8ee3..07f4be019 100644 --- a/_pytest/runner.py +++ b/_pytest/runner.py @@ -554,14 +554,21 @@ def importorskip(modname, minversion=None): __version__ attribute. If no minversion is specified the a skip is only triggered if the module can not be imported. """ + import warnings __tracebackhide__ = True compile(modname, '', 'eval') # to catch syntaxerrors should_skip = False - try: - __import__(modname) - except ImportError: - # Do not raise chained exception here(#1485) - should_skip = True + + with warnings.catch_warnings(): + # make sure to ignore ImportWarnings that might happen because + # of existing directories with the same name we're trying to + # import but without a __init__.py file + warnings.simplefilter('ignore') + try: + __import__(modname) + except ImportError: + # Do not raise chained exception here(#1485) + should_skip = True if should_skip: raise Skipped("could not import %r" %(modname,), allow_module_level=True) mod = sys.modules[modname] diff --git a/tox.ini b/tox.ini index f8ea5fabd..5c103f94c 100644 --- a/tox.ini +++ b/tox.ini @@ -181,6 +181,10 @@ filterwarnings= error ignore:bad escape.*:DeprecationWarning:re # produced by path.readlines ignore:.*U.*mode is deprecated:DeprecationWarning + # produced by pytest-xdist + ignore:.*type argument to addoption.*:DeprecationWarning + # produced by python >=3.5 on execnet (pytest-xdist) + ignore:.*inspect.getargspec.*deprecated, use inspect.signature.*:DeprecationWarning [flake8] ignore =E401,E225,E261,E128,E124,E301,E302,E121,E303,W391,E501,E231,E126,E701,E265,E241,E251,E226,E101,W191,E131,E203,E122,E123,E271,E712,E222,E127,E125,E221,W292,E111,E113,E293,E262,W293,E129,E702,E201,E272,E202,E704,E731,E402