diff --git a/_pytest/monkeypatch.py b/_pytest/monkeypatch.py index c394d23bb..4d3abc0dc 100644 --- a/_pytest/monkeypatch.py +++ b/_pytest/monkeypatch.py @@ -1,7 +1,6 @@ """ monkeypatching and mocking functionality. """ -import os, sys, inspect -import pytest +import os, sys def pytest_funcarg__monkeypatch(request): """The returned ``monkeypatch`` funcarg provides these @@ -28,6 +27,7 @@ def pytest_funcarg__monkeypatch(request): def derive_importpath(import_path): + import pytest if not isinstance(import_path, str) or "." not in import_path: raise TypeError("must be absolute import path string, not %r" % (import_path,)) @@ -82,6 +82,7 @@ class monkeypatch: which means it will raise). """ __tracebackhide__ = True + import inspect if value is notset: if not isinstance(target, str): diff --git a/_pytest/terminal.py b/_pytest/terminal.py index 1e928dc7d..ab132d45e 100644 --- a/_pytest/terminal.py +++ b/_pytest/terminal.py @@ -37,11 +37,11 @@ def pytest_configure(config): # we try hard to make printing resilient against # later changes on FD level. (unless capturing is off/sys) stdout = sys.stdout - if hasattr(os, "dup"): + if hasattr(os, "dup") and hasattr(stdout, "fileno"): try: newstdout = py.io.dupfile(stdout, buffering=1, encoding=stdout.encoding) - except ValueError: + except (AttributeError, ValueError): pass else: assert stdout.encoding == newstdout.encoding