New submission from Brian Skinn <bsk...@alum.mit.edu>:

In [this project](https://github.com/bskinn/stdio-mgr) of mine, I have a tox 
matrix set up with Pythons from 3.3. to 3.8. I have pytest set up to run 
doctest on my 
[`README.rst`](https://github.com/bskinn/stdio-mgr/blob/6444cce8e5866e2d519c1c0630551d8867f30c9a/README.rst).
  For Pythons 3.4 to 3.7 (3.4.10, 3.5.7, 3.6.8, 3.7.2), the following doctest 
example passes:

```
>>> import warnings
>>> with stdio_mgr() as (in_, out_, err_):
...     warnings.warn("'foo' has no 'bar'")
...     err_cap = err_.getvalue()
>>> err_cap
"...UserWarning: 'foo' has no 'bar'\n..."
```

Under Python 3.8.0a3, though, it fails (actual local paths elided):

```
$ tox -re py38-attrs_latest
.package recreate: .../.tox/.package
.package installdeps: wheel, setuptools, attrs>=17.1
py38-attrs_latest recreate: .../.tox/py38-attrs_latest
py38-attrs_latest installdeps: attrs, pytest
py38-attrs_latest inst: .../.tox/.tmp/package/1/stdio-mgr-1.0.2.dev1.tar.gz
py38-attrs_latest installed: 
atomicwrites==1.3.0,attrs==19.1.0,more-itertools==7.0.0,pluggy==0.9.0,py==1.8.0,pytest==4.4.1,six==1.12.0,stdio-mgr==1.0.2.dev1
py38-attrs_latest run-test-pre: PYTHONHASHSEED='2720295779'
py38-attrs_latest run-test: commands[0] | pytest
===============================================================================================
 test session starts 
================================================================================================
platform linux -- Python 3.8.0a3, pytest-4.4.1, py-1.8.0, pluggy-0.9.0
cachedir: .tox/py38-attrs_latest/.pytest_cache
rootdir: ..., inifile: tox.ini
collected 6 items                                                               
                                                                                
                                                   

README.rst F                                                                    
                                                                                
                                             [ 16%]
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'

.../README.rst:86: DocTestFailure
========================================================================================
 1 failed, 5 passed in 0.06 seconds 
========================================================================================
ERROR: InvocationError for command .../.tox/py38-attrs_latest/bin/pytest 
(exited with code 1)
_____________________________________________________________________________________________________
 summary 
______________________________________________________________________________________________________
ERROR:   py38-attrs_latest: commands failed

```

If I change the doctest in README to the following, where the expected output 
is surrounded by single-quotes instead of double-quotes, and the internal 
single quotes are escaped, it passes fine in 3.8.0a3:

```
>>> import warnings
    >>> with stdio_mgr() as (in_, out_, err_):
    ...     warnings.warn("'foo' has no 'bar'")
    ...     err_cap = err_.getvalue()
    >>> err_cap
    '...UserWarning: \'foo\' has no \'bar\'\n...'
```

But, naturally, it fails in 3.7 and below.

It *looks* like this is probably a glitch somewhere in 3.8.0a3, where this 
string containing single quotes is rendered (at the REPL?) using enclosing 
single quotes and escaped internal single quotes, rather than enclosing 
double-quotes and non-escaped internal single-quotes?

----------
components: Library (Lib)
messages: 340637
nosy: bskinn
priority: normal
severity: normal
status: open
title: Change (regression?) in v3.8.0a3 doctest output after capturing the 
stderr output from a raised warning
type: behavior
versions: Python 3.8

_______________________________________
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