Skip to content

Add new capture option, "forget", to not print to stdout when test fails #1233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 23 commits into from
Closed
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
efd8c8f
Add new capture type: forget
aikchar Oct 28, 2015
3d802a7
Add new capture class for 'forget'
aikchar Oct 28, 2015
3f6f12d
Modify 'forget' to delete the files after capture ends
aikchar Oct 28, 2015
929e590
Do not append captured output to sections (trying an idea)
aikchar Oct 28, 2015
2676cf3
Last idea removed all stdout output
aikchar Oct 28, 2015
f46591f
Change the file that is deleted (trying an idea)
aikchar Oct 28, 2015
59c2fd1
Change the file that is deleted (trying an idea)
aikchar Oct 28, 2015
50568b6
Bump version number
aikchar Oct 28, 2015
165474e
Change the file that is deleted (trying an idea)
aikchar Oct 28, 2015
9bf477e
Change the file that is deleted (trying an idea)
aikchar Oct 28, 2015
bada508
Bump version number
aikchar Oct 28, 2015
12cde16
Change the file that is deleted (trying an idea)
aikchar Oct 28, 2015
9493711
Try not writing data out
aikchar Oct 28, 2015
b788cf8
Change the file that is deleted (trying an idea)
aikchar Oct 28, 2015
09588c2
Read file that was closed (trying an idea)
aikchar Oct 28, 2015
a444498
Read file that will be closed (trying an idea)
aikchar Oct 28, 2015
0927ab6
Read file that will be closed (trying an idea)
aikchar Oct 28, 2015
1e69bc9
Set syscapture to nocapture (trying an idea)
aikchar Oct 28, 2015
b53a76b
Blindly trying things out
aikchar Oct 28, 2015
0639c2b
Subclass 'forget' from 'fd'
aikchar Oct 28, 2015
9018d3f
Fixed typo
aikchar Oct 28, 2015
77cdee5
Clean up
aikchar Oct 28, 2015
d7221af
Merge branch 'master' of https://github.com/pytest-dev/pytest
aikchar Dec 7, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions _pytest/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def pytest_addoption(parser):
group._addoption(
'--capture', action="store",
default="fd" if hasattr(os, "dup") else "sys",
metavar="method", choices=['fd', 'sys', 'no'],
help="per-test capturing method: one of fd|sys|no.")
metavar="method", choices=['fd', 'sys', 'no', 'forget'],
help="per-test capturing method: one of fd|sys|no|forget.")
group._addoption(
'-s', action="store_const", const="no", dest="capture",
help="shortcut for --capture=no.")
Expand Down Expand Up @@ -63,6 +63,8 @@ def _getcapture(self, method):
return MultiCapture(out=True, err=True, Capture=FDCapture)
elif method == "sys":
return MultiCapture(out=True, err=True, Capture=SysCapture)
elif method == "forget":
return MultiCapture(out=True, err=True, Capture=ForgetCapture)
elif method == "no":
return MultiCapture(out=False, err=False, in_=False)
else:
Expand Down Expand Up @@ -418,6 +420,28 @@ def writeorg(self, data):
self._old.flush()


class ForgetCapture(FDCapture):
""" Capture IO to/from a given os-level filedescriptor and forget it. """

def __init__(self, targetfd, tmpfile=None):
super().__init__(targetfd, tmpfile=None)

def __repr__(self):
return "<ForgetCapture %s oldfd=%s>" % (self.targetfd, self.targetfd_save)

def snap(self):
f = self.tmpfile
f.seek(0)
res = f.read()
if res:
enc = getattr(f, "encoding", None)
if enc and isinstance(res, bytes):
res = py.builtin._totext(res, enc, "replace")
f.truncate(0)
f.seek(0)
return ''


class DontReadFromInput:
"""Temporary stub class. Ideally when stdin is accessed, the
capturing should be turned off, with possibly all data captured
Expand Down