From 3c3fc3bb9dcd4ba9902e59c8160163d0c962dbe1 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 15 Mar 2018 21:25:50 -0400 Subject: [PATCH 1/5] Add test capturing new expectation. Ref #3314. --- testing/test_capture.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/testing/test_capture.py b/testing/test_capture.py index 4f9028fca..7fccc055d 100644 --- a/testing/test_capture.py +++ b/testing/test_capture.py @@ -751,7 +751,8 @@ def test_dontreadfrominput(): assert not f.isatty() pytest.raises(IOError, f.read) pytest.raises(IOError, f.readlines) - pytest.raises(IOError, iter, f) + iter_f = iter(f) + pytest.raises(IOError, next, iter_f) pytest.raises(UnsupportedOperation, f.fileno) f.close() # just for completeness @@ -764,7 +765,8 @@ def test_dontreadfrominput_buffer_python3(): assert not fb.isatty() pytest.raises(IOError, fb.read) pytest.raises(IOError, fb.readlines) - pytest.raises(IOError, iter, fb) + iter_f = iter(f) + pytest.raises(IOError, next, iter_f) pytest.raises(ValueError, fb.fileno) f.close() # just for completeness From 2f47624b19d53db7667c54dd6bcf2232e1dc24e3 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 15 Mar 2018 21:26:40 -0400 Subject: [PATCH 2/5] Allow DontReadFromInput to produce iterator without error. Fixes #3314. --- _pytest/capture.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/_pytest/capture.py b/_pytest/capture.py index 6e2139445..6545e6fa3 100644 --- a/_pytest/capture.py +++ b/_pytest/capture.py @@ -574,7 +574,10 @@ class DontReadFromInput(object): raise IOError("reading from stdin while output is captured") readline = read readlines = read - __iter__ = read + __next__ = read + + def __iter__(self): + return self def fileno(self): raise UnsupportedOperation("redirected stdin is pseudofile, " From 965a030564be02f5926c1a579ff59dabf5702e37 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 15 Mar 2018 21:30:29 -0400 Subject: [PATCH 3/5] Add changelog. Ref #3314. --- changelog/3314.bugfix.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog/3314.bugfix.rst diff --git a/changelog/3314.bugfix.rst b/changelog/3314.bugfix.rst new file mode 100644 index 000000000..4b671ec21 --- /dev/null +++ b/changelog/3314.bugfix.rst @@ -0,0 +1,3 @@ +During test collection, when stdin is not allowed to be read, the +``DontReadFromStdin`` object still allow itself to be iterable and +resolved to an iterator without crashing. From b66019202ec389d5430434ace3068a8eb405402a Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 15 Mar 2018 21:33:58 -0400 Subject: [PATCH 4/5] Fix test failure on Python 2. Ref #3314. --- _pytest/capture.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_pytest/capture.py b/_pytest/capture.py index 6545e6fa3..9f4f41c41 100644 --- a/_pytest/capture.py +++ b/_pytest/capture.py @@ -560,7 +560,7 @@ class SysCaptureBinary(SysCapture): return res -class DontReadFromInput(object): +class DontReadFromInput(six.Iterator): """Temporary stub class. Ideally when stdin is accessed, the capturing should be turned off, with possibly all data captured so far sent to the screen. This should be configurable, though, From 17468fc99c0bee8efaffb7dfb506f23e3b30145f Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Fri, 16 Mar 2018 00:04:28 -0300 Subject: [PATCH 5/5] Fix caplog docstring: indentation caused errors during docs build --- _pytest/logging.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/_pytest/logging.py b/_pytest/logging.py index c920659a5..b265ca34d 100644 --- a/_pytest/logging.py +++ b/_pytest/logging.py @@ -292,8 +292,7 @@ def caplog(request): * caplog.text() -> string containing formatted log output * caplog.records() -> list of logging.LogRecord instances * caplog.record_tuples() -> list of (logger_name, level, message) tuples - * caplog.clear() -> clear captured records and formatted log output - string + * caplog.clear() -> clear captured records and formatted log output string """ result = LogCaptureFixture(request.node) yield result