This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author xtreak
Recipients brett.cannon, bskinn, takluyver, vstinner, xtreak
Date 2019-04-22.07:11:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1555917101.14.0.753142459153.issue36695@roundup.psfhosted.org>
In-reply-to
Content
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 <takowl@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
History
Date User Action Args
2019-04-22 07:11:41xtreaksetrecipients: + xtreak, brett.cannon, vstinner, takluyver, bskinn
2019-04-22 07:11:41xtreaksetmessageid: <1555917101.14.0.753142459153.issue36695@roundup.psfhosted.org>
2019-04-22 07:11:41xtreaklinkissue36695 messages
2019-04-22 07:11:40xtreakcreate