Karthikeyan Singaravelan <tir.kar...@gmail.com> added the comment:

I tried bisecting and got to this commit 
11a896652ee98aa44e59ed25237f9efb56635dcf (issue33375) . Seems this changes 
warning reporting output to add filename. I guess it's better to change the 
doctest to adopt this change. I have added the devs on the issue for 
confirmation.

commit 11a896652ee98aa44e59ed25237f9efb56635dcf (HEAD)
Author: Thomas Kluyver <tak...@gmail.com>
Date:   Fri Jun 8 21:28:37 2018 +0200

    bpo-33375: Get filename for warnings from frame.f_code.co_filename (GH-6622)

    More consistent with how other parts of Python find the filename (e.g. 
tracebacks and pdb).

$ cat ../backups/bpo36695_1.py
def foo():
    '''
    >>> import warnings, io
    >>> from contextlib import redirect_stderr
    >>> f = io.StringIO()
    >>> with redirect_stderr(f):
    ...     warnings.warn("'foo' has no 'bar'")
    ...     err_cap = f.getvalue()
    >>> print(err_cap)
    '''
    pass

➜  cpython git:(11a896652e) ./python.exe -m doctest ../backups/bpo36695_1.py
**********************************************************************
File "../backups/bpo36695_1.py", line 9, in bpo36695_1.foo
Failed example:
    print(err_cap)
Expected nothing
Got:
    <doctest bpo36695_1.foo[3]>:2: UserWarning: 'foo' has no 'bar'
      warnings.warn("'foo' has no 'bar'")
    <BLANKLINE>
**********************************************************************
1 items had failures:
   1 of   5 in bpo36695_1.foo
***Test Failed*** 1 failures.

# Before 11a896652ee98aa44e59ed25237f9efb56635dcf

➜  cpython git:(11a896652e) git checkout 
11a896652ee98aa44e59ed25237f9efb56635dcf~1
Previous HEAD position was 11a896652e bpo-33375: Get filename for warnings from 
frame.f_code.co_filename (GH-6622)
HEAD is now at 3b0b90c8c3 bpo-33800: Fix default argument for parameter 
dict_type of ConfigParser/RawConfigParser (GH-7494)
➜  cpython git:(3b0b90c8c3) make -s -j4 > /dev/null
➜  cpython git:(3b0b90c8c3) ./python.exe -m doctest ../backups/bpo36695_1.py
**********************************************************************
File "../backups/bpo36695_1.py", line 9, in bpo36695_1.foo
Failed example:
    print(err_cap)
Expected nothing
Got:
    ../backups/bpo36695_1.py:2: UserWarning: 'foo' has no 'bar'
      '''
    <BLANKLINE>
**********************************************************************
1 items had failures:
   1 of   5 in bpo36695_1.foo
***Test Failed*** 1 failures.


I can replicate test failure as below with 
11a896652ee98aa44e59ed25237f9efb56635dcf and passes with the commit before it.

README.rst F                                                                    
              [ 20%]
tests/test_stdiomgr_base.py ....                                                
              [100%]

============================================= FAILURES 
==============================================
_______________________________________ [doctest] README.rst 
________________________________________
077
078 **Mock** ``stderr``\ **:**
079
080 .. code ::
081
082     >>> import warnings
083     >>> with stdio_mgr() as (in_, out_, err_):
084     ...     warnings.warn("'foo' has no 'bar'")
085     ...     err_cap = err_.getvalue()
086     >>> err_cap
Expected:
    "...UserWarning: 'foo' has no 'bar'\n..."
Got:
    '<doctest README.rst[4]>:2: UserWarning: \'foo\' has no \'bar\'\n  
warnings.warn("\'foo\' has no \'bar\'")\n'

/home/karthi/stdio-mgr/README.rst:86: DocTestFailure

----------
nosy: +brett.cannon, takluyver, vstinner

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue36695>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to