[issue8048] doctest assumes sys.displayhook hasn't been touched
Noam Yorav-Raphael added the comment: Ok, here's a patch (against current svn of Python 2) with a test case. I had to fix three tests which combined pdb and doctest, since now, when run under doctest, pdb steps into the displayhook because it's a Python function and not a built-in function. The fix is just to return from the displayhook. If you wish, I can prepare a patch for Python 3. -- Added file: http://bugs.python.org/file16436/diff ___ Python tracker <http://bugs.python.org/issue8048> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8048] doctest assumes sys.displayhook hasn't been touched
Noam Yorav-Raphael added the comment: Here is a better and much shorter patch: I use sys.__displayhook__ instead of implementing it in Python, which has the nice side effect of not changing pdb behaviour. -- Added file: http://bugs.python.org/file16581/patch ___ Python tracker <http://bugs.python.org/issue8048> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8213] Python 3 ignored PYTHONUNBUFFERED and -u
New submission from Noam Yorav-Raphael : Hello, Python 3.1 ignored the PYTHONUNBUFFERED environment variable and the '-u' switch (which do the same thing): stdout remains buffered even when the flag is raised. To reproduce, run: > python3 -u -c 'import time, sys; sys.stdout.write("a"); time.sleep(1); > sys.stdout.write("\n")' You can see that it first waits a second and then 'a' is printed. I'm using Ubuntu 9.10. Tested this on both the 3.1.1 installed and svn checkout (revision 79345). This follows a bug report: https://bugs.launchpad.net/dreampie/+bug/545012 which was reported on win32, so the problem is there too. -- components: IO messages: 101584 nosy: noam severity: normal status: open title: Python 3 ignored PYTHONUNBUFFERED and -u type: behavior versions: Python 3.1 ___ Python tracker <http://bugs.python.org/issue8213> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8213] Python 3 ignored PYTHONUNBUFFERED and -u
Noam Yorav-Raphael added the comment: I typed "man python3" on ubuntu 9.10 and nothing was explained about that - I now checked and found out that it displayed the python2 man page. I don't know where to find the Python 3 man page. I don't quite see the point in having the streams buffered in one level and unbuffered in another, but I guess there's a reason. Anyway, how can I make those streams entirely unbuffered? This is for an interactive shell called DreamPie (dreampie.sourceforge.net), and I want to resemble the behavior of the regular shell as close as possible, and it's completely unbuffered. -- ___ Python tracker <http://bugs.python.org/issue8213> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8213] Python 3 ignored PYTHONUNBUFFERED and -u
Noam Yorav-Raphael added the comment: I can call flush() after the user code was executed, but a code like this: >>> for i in range(10): ... print(i, end=' ') ... time.sleep(1) will show the numbers only after 10 seconds, while I would like a number printed every second. I now see that that's what the regular shell does, so it's probably not a very big deal. -- ___ Python tracker <http://bugs.python.org/issue8213> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue26092] doctest should allow custom sys.displayhook
Noam Yorav-Raphael added the comment: Hi, I think that using mock.patch to fix the problem is fine. I personally haven't encountered this problem in the past years, so whatever you decide is fine by me. Thanks! Noam On Mon, Apr 26, 2021 at 10:08 AM Sergey B Kirpichev wrote: > > Sergey B Kirpichev added the comment: > > Tim, lets decide on this simple issue. > > To me, https://bugs.python.org/issue8048 was obviously a bad thing. > While it "fixes" one application, which customize sys.displayhook in a > strange way - it break testing almost everyone, which do sys.displayhook > customization. See e.g. > https://github.com/sympy/sympy/blob/master/conftest.py or > https://github.com/diofant/diofant/blob/master/conftest.py. BTW, SymPy > is far more popular library than dreampie, which is py2-only and looks > unmaintained. > > Last, but not least - introduced doctest's behaviour wasn't documented. > It break things in a surprising way and do this silently... There is a > documentation issue if you decide to keep this "feature". > > Noam, what do you think about fixing your problem with mock.patch? > > >>> import sys > >>> from unittest.mock import patch > >>> with patch('sys.displayhook', sys.__displayhook__): > ... doctest.testmod() > > Tentative patch attached. > > -- > keywords: +patch > Added file: https://bugs.python.org/file49985/doctest-displayhook.diff > > ___ > Python tracker > <https://bugs.python.org/issue26092> > ___ > -- ___ Python tracker <https://bugs.python.org/issue26092> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue26092] doctest should allow custom sys.displayhook
Noam Yorav-Raphael added the comment: Yes, sorry, I didn't remember the history exactly. I don't have a strong opinion. I'm okay with reverting the behavior to use sys.displayhook. Thanks, Noam -- ___ Python tracker <https://bugs.python.org/issue26092> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue26092] doctest should allow custom sys.displayhook
Noam Yorav-Raphael added the comment: Tim, thanks for letting me know. I certainly don't mind if you close this bug, since it undoes my old (and still relevant) fix. -- nosy: +noamraph ___ Python tracker <https://bugs.python.org/issue26092> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue35330] When using mock to wrap an existing object, side_effect requires return_value
New submission from Noam Yorav-Raphael : When using mock to wrap an existing object, and using side_effect to set a function to wrap a method, I would expect the wrapper function to be called instead of the wrapped function, and its return value to be returned. Instead, both the wrapper function and the wrapped functions are being called, and the return value of the wrapped function is returned. If, in addition to side_effect, return_value is set, the return_value is ignored, but my expected behavior actually happens: only the wrapper function is called, and its return value is returned. Python 3.7.0 (default, Aug 22 2018, 20:50:05) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from unittest import mock >>> class MyClass(object): ... def func(self): ... print('func called') ... return 1 ... >>> c = MyClass() >>> m = mock.Mock(wraps=c) >>> def func2(): ... print('func2 called') ... return 2 ... >>> m.func.side_effect = func2 >>> m.func() func2 called func called 1 >>> m.func.return_value = 3 >>> m.func() func2 called 2 -- components: Library (Lib) messages: 330540 nosy: noamraph priority: normal severity: normal status: open title: When using mock to wrap an existing object, side_effect requires return_value type: behavior ___ Python tracker <https://bugs.python.org/issue35330> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com