Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion src/_pytest/_code/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import traceback
from inspect import CO_VARARGS
from inspect import CO_VARKEYWORDS
from io import StringIO
from traceback import format_exception_only
from types import CodeType
from types import TracebackType
Expand Down Expand Up @@ -865,7 +866,7 @@ class TerminalRepr:
def __str__(self):
# FYI this is called from pytest-xdist's serialization of exception
# information.
io = py.io.TextIO()
io = StringIO()
tw = py.io.TerminalWriter(file=io)
self.toterminal(tw)
return io.getvalue().strip()
Expand Down
7 changes: 3 additions & 4 deletions src/_pytest/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import logging
import re
from contextlib import contextmanager

import py
from io import StringIO

import pytest
from _pytest.compat import nullcontext
Expand Down Expand Up @@ -218,7 +217,7 @@ class LogCaptureHandler(logging.StreamHandler):

def __init__(self):
"""Creates a new log handler."""
logging.StreamHandler.__init__(self, py.io.TextIO())
logging.StreamHandler.__init__(self, StringIO())
self.records = []

def emit(self, record):
Expand All @@ -228,7 +227,7 @@ def emit(self, record):

def reset(self):
self.records = []
self.stream = py.io.TextIO()
self.stream = StringIO()


class LogCaptureFixture:
Expand Down
3 changes: 2 additions & 1 deletion src/_pytest/pytester.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import traceback
from collections.abc import Sequence
from fnmatch import fnmatch
from io import StringIO
from weakref import WeakKeyDictionary

import py
Expand Down Expand Up @@ -1218,7 +1219,7 @@ def getdecoded(out):

class LineComp:
def __init__(self):
self.stringio = py.io.TextIO()
self.stringio = StringIO()

def assert_contains_lines(self, lines2):
"""Assert that lines2 are contained (linearly) in lines1.
Expand Down
3 changes: 2 additions & 1 deletion src/_pytest/reports.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from io import StringIO
from pprint import pprint
from typing import Optional
from typing import Union
Expand Down Expand Up @@ -180,7 +181,7 @@ def _from_json(cls, reportdict):

def _report_unserialization_failure(type_name, report_class, reportdict):
url = "https://github.com/pytest-dev/pytest/issues"
stream = py.io.TextIO()
stream = StringIO()
pprint("-" * 100, stream=stream)
pprint("INTERNALERROR: Unknown entry type returned: %s" % type_name, stream=stream)
pprint("report_name: %s" % report_class, stream=stream)
Expand Down
9 changes: 4 additions & 5 deletions testing/test_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
import subprocess
import sys
import textwrap
from io import StringIO
from io import UnsupportedOperation

import py

import pytest
from _pytest import capture
from _pytest.capture import CaptureManager
Expand Down Expand Up @@ -892,10 +891,10 @@ def test_dupfile_on_bytesio():


def test_dupfile_on_textio():
tio = py.io.TextIO()
f = capture.safe_text_dupfile(tio, "wb")
sio = StringIO()
f = capture.safe_text_dupfile(sio, "wb")
f.write("hello")
assert tio.getvalue() == "hello"
assert sio.getvalue() == "hello"
assert not hasattr(f, "name")


Expand Down
13 changes: 6 additions & 7 deletions testing/test_resultlog.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os

import py
from io import StringIO

import _pytest._code
import pytest
Expand All @@ -13,15 +12,15 @@

def test_write_log_entry():
reslog = ResultLog(None, None)
reslog.logfile = py.io.TextIO()
reslog.logfile = StringIO()
reslog.write_log_entry("name", ".", "")
entry = reslog.logfile.getvalue()
assert entry[-1] == "\n"
entry_lines = entry.splitlines()
assert len(entry_lines) == 1
assert entry_lines[0] == ". name"

reslog.logfile = py.io.TextIO()
reslog.logfile = StringIO()
reslog.write_log_entry("name", "s", "Skipped")
entry = reslog.logfile.getvalue()
assert entry[-1] == "\n"
Expand All @@ -30,7 +29,7 @@ def test_write_log_entry():
assert entry_lines[0] == "s name"
assert entry_lines[1] == " Skipped"

reslog.logfile = py.io.TextIO()
reslog.logfile = StringIO()
reslog.write_log_entry("name", "s", "Skipped\n")
entry = reslog.logfile.getvalue()
assert entry[-1] == "\n"
Expand All @@ -39,7 +38,7 @@ def test_write_log_entry():
assert entry_lines[0] == "s name"
assert entry_lines[1] == " Skipped"

reslog.logfile = py.io.TextIO()
reslog.logfile = StringIO()
longrepr = " tb1\n tb 2\nE tb3\nSome Error"
reslog.write_log_entry("name", "F", longrepr)
entry = reslog.logfile.getvalue()
Expand Down Expand Up @@ -118,7 +117,7 @@ def test_internal_exception(self, style):
raise ValueError
except ValueError:
excinfo = _pytest._code.ExceptionInfo.from_current()
reslog = ResultLog(None, py.io.TextIO())
reslog = ResultLog(None, StringIO())
reslog.pytest_internalerror(excinfo.getrepr(style=style))
entry = reslog.logfile.getvalue()
entry_lines = entry.splitlines()
Expand Down
3 changes: 2 additions & 1 deletion testing/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import sys
import textwrap
from io import StringIO

import pluggy
import py
Expand Down Expand Up @@ -268,7 +269,7 @@ def test_foobar():

def test_rewrite(self, testdir, monkeypatch):
config = testdir.parseconfig()
f = py.io.TextIO()
f = StringIO()
monkeypatch.setattr(f, "isatty", lambda *args: True)
tr = TerminalReporter(config, f)
tr._tw.fullwidth = 10
Expand Down