Skip to content

AttributeError: 'OutputWriter' object has no attribute 'isatty' #1447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ldiary opened this issue Mar 10, 2016 · 2 comments
Closed

AttributeError: 'OutputWriter' object has no attribute 'isatty' #1447

ldiary opened this issue Mar 10, 2016 · 2 comments

Comments

@ldiary
Copy link

ldiary commented Mar 10, 2016

Here is my sample code where I am running pytest programmatically and I am overriding the sys.stdout.

def multi_procesed(arguments, path, run_id, logfile):
    sys.stdout = OutputWriter(run_id)
    exit_status = pytest.main(args=arguments)

Above code encounters the following error in pytest==2.9.0.

INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/home/ldiary/py351env/lib/python3.5/site-packages/_pytest/main.py", line 90, in wrap_session
INTERNALERROR>     config._do_configure()
INTERNALERROR>   File "/home/ldiary/py351env/lib/python3.5/site-packages/_pytest/config.py", line 834, in _do_configure
INTERNALERROR>     self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR>   File "/home/ldiary/py351env/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 729, in call_historic
INTERNALERROR>     self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/home/ldiary/py351env/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/home/ldiary/py351env/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR>   File "/home/ldiary/py351env/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/home/ldiary/py351env/lib/python3.5/site-packages/_pytest/terminal.py", line 47, in pytest_configure
INTERNALERROR>     reporter = TerminalReporter(config, sys.stdout)
INTERNALERROR>   File "/home/ldiary/py351env/lib/python3.5/site-packages/_pytest/terminal.py", line 115, in __init__
INTERNALERROR>     self.isatty = file.isatty()
INTERNALERROR> AttributeError: 'OutputWriter' object has no attribute 'isatty'

Currently, I am using the following workaround.

C:\Users\ernesto.luzon\pytest>git diff _pytest\terminal.py
diff --git a/_pytest/terminal.py b/_pytest/terminal.py
index 825f553..22c805e 100644
--- a/_pytest/terminal.py
+++ b/_pytest/terminal.py
@@ -112,7 +112,10 @@ class TerminalReporter:
         self.currentfspath = None
         self.reportchars = getreportopt(config)
         self.hasmarkup = self._tw.hasmarkup
-        self.isatty = file.isatty()
+        try:
+            self.isatty = file.isatty()
+        except AttributeError:
+            self.isatty = False

     def hasopt(self, char):
         char = {'xfailed': 'x', 'skipped': 's'}.get(char, char)
@The-Compiler
Copy link
Member

I don't think this is a pytest bug - the docs for io.IOBase says it has an isatty attribute, so your OutputWriter should have that as well.

@ldiary
Copy link
Author

ldiary commented Mar 10, 2016

Okay, thanks!
I have no problem implementing isatty in my rudimentary OutputWriter and I think it's a better solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants