manual: remove dependence on six

This commit is contained in:
Anthony Sottile 2019-06-02 15:53:45 -07:00 committed by Bruno Oliveira
parent ca1efd57bd
commit 5dcf85c17e
11 changed files with 42 additions and 56 deletions

View File

@ -4,7 +4,6 @@ from setuptools import setup
# remove _width_of_current_line in terminal.py
INSTALL_REQUIRES = [
"py>=1.5.0",
"six>=1.10.0",
"packaging",
"attrs>=17.4.0",
"more-itertools>=4.0.0",

View File

@ -14,7 +14,6 @@ from importlib.util import spec_from_file_location
import atomicwrites
import py
import six
from _pytest._io.saferepr import saferepr
from _pytest.assertion import util
@ -612,7 +611,7 @@ class AssertionRewriter(ast.NodeVisitor):
# Insert some special imports at the top of the module but after any
# docstrings and __future__ imports.
aliases = [
ast.alias(six.moves.builtins.__name__, "@py_builtins"),
ast.alias("builtins", "@py_builtins"),
ast.alias("_pytest.assertion.rewrite", "@pytest_ar"),
]
doc = getattr(mod, "docstring", None)

View File

@ -9,7 +9,6 @@ from collections import OrderedDict
import attr
import py
import six
import _pytest
from _pytest import nodes
@ -848,10 +847,10 @@ class FixtureDef:
except: # noqa
exceptions.append(sys.exc_info())
if exceptions:
e = exceptions[0]
_, val, tb = exceptions[0]
# Ensure to not keep frame references through traceback.
del exceptions
six.reraise(*e)
raise val.with_traceback(tb)
finally:
hook = self._fixturemanager.session.gethookproxy(request.node.fspath)
hook.pytest_fixture_post_finalizer(fixturedef=self, request=request)
@ -877,7 +876,8 @@ class FixtureDef:
result, cache_key, err = cached_result
if my_cache_key == cache_key:
if err is not None:
six.reraise(*err)
_, val, tb = err
raise val.with_traceback(tb)
else:
return result
# we have a previous but differently parametrized fixture instance
@ -950,7 +950,7 @@ def wrap_function_to_error_out_if_called_directly(function, fixture_marker):
name=fixture_marker.name or function.__name__
)
@six.wraps(function)
@functools.wraps(function)
def result(*args, **kwargs):
fail(message, pytrace=False)

View File

@ -4,7 +4,6 @@ import re
from contextlib import contextmanager
import py
import six
import pytest
from _pytest.compat import dummy_context_manager
@ -66,34 +65,31 @@ class ColoredLevelFormatter(logging.Formatter):
return super().format(record)
if not six.PY2:
# Formatter classes don't support format styles in PY2
class PercentStyleMultiline(logging.PercentStyle):
"""A logging style with special support for multiline messages.
class PercentStyleMultiline(logging.PercentStyle):
"""A logging style with special support for multiline messages.
If the message of a record consists of multiple lines, this style
formats the message as if each line were logged separately.
"""
If the message of a record consists of multiple lines, this style
formats the message as if each line were logged separately.
"""
@staticmethod
def _update_message(record_dict, message):
tmp = record_dict.copy()
tmp["message"] = message
return tmp
@staticmethod
def _update_message(record_dict, message):
tmp = record_dict.copy()
tmp["message"] = message
return tmp
def format(self, record):
if "\n" in record.message:
lines = record.message.splitlines()
formatted = self._fmt % self._update_message(record.__dict__, lines[0])
# TODO optimize this by introducing an option that tells the
# logging framework that the indentation doesn't
# change. This allows to compute the indentation only once.
indentation = _remove_ansi_escape_sequences(formatted).find(lines[0])
lines[0] = formatted
return ("\n" + " " * indentation).join(lines)
else:
return self._fmt % record.__dict__
def format(self, record):
if "\n" in record.message:
lines = record.message.splitlines()
formatted = self._fmt % self._update_message(record.__dict__, lines[0])
# TODO optimize this by introducing an option that tells the
# logging framework that the indentation doesn't
# change. This allows to compute the indentation only once.
indentation = _remove_ansi_escape_sequences(formatted).find(lines[0])
lines[0] = formatted
return ("\n" + " " * indentation).join(lines)
else:
return self._fmt % record.__dict__
def get_option_ini(config, *names):
@ -464,8 +460,7 @@ class LoggingPlugin:
else:
formatter = logging.Formatter(log_format, log_date_format)
if not six.PY2:
formatter._style = PercentStyleMultiline(formatter._style._fmt)
formatter._style = PercentStyleMultiline(formatter._style._fmt)
return formatter
def _setup_cli_logging(self):

View File

@ -5,7 +5,6 @@ import sys
from time import time
import attr
import six
from .reports import CollectErrorRepr
from .reports import CollectReport
@ -304,7 +303,8 @@ class SetupState:
if exc is None:
exc = sys.exc_info()
if exc:
six.reraise(*exc)
_, val, tb = exc
raise val.with_traceback(tb)
def _teardown_with_finalization(self, colitem):
self._callfinalizers(colitem)
@ -339,7 +339,8 @@ class SetupState:
if exc is None:
exc = sys.exc_info()
if exc:
six.reraise(*exc)
_, val, tb = exc
raise val.with_traceback(tb)
def prepare(self, colitem):
""" setup objects along the collector chain to the test-method
@ -350,7 +351,8 @@ class SetupState:
# check if the last collection node has raised an error
for col in self.stack:
if hasattr(col, "_prepare_exc"):
six.reraise(*col._prepare_exc)
_, val, tb = col._prepare_exc
raise val.with_traceback(tb)
for col in needed_collectors[len(self.stack) :]:
self.stack.append(col)
try:

View File

@ -5,8 +5,6 @@ import ast
import inspect
import sys
import six
import _pytest._code
import pytest
from _pytest._code import Source

View File

@ -1,9 +1,7 @@
import logging
import py.io
import six
import pytest
from _pytest.logging import ColoredLevelFormatter
@ -38,9 +36,6 @@ def test_coloredlogformatter():
assert output == ("dummypath 10 INFO Test Message")
@pytest.mark.skipif(
six.PY2, reason="Formatter classes don't support format styles in PY2"
)
def test_multiline_message():
from _pytest.logging import PercentStyleMultiline

View File

@ -1,8 +1,7 @@
import io
import os
import re
import six
import pytest
@ -885,7 +884,7 @@ def test_live_logging_suspends_capture(has_capture_manager, request):
yield
self.calls.append("exit disabled")
class DummyTerminal(six.StringIO):
class DummyTerminal(io.StringIO):
def section(self, *args, **kwargs):
pass

View File

@ -1357,9 +1357,8 @@ class TestFixtureManagerParseFactories:
def test_parsefactories_conftest_and_module_and_class(self, testdir):
testdir.makepyfile(
"""
"""\
import pytest
import six
@pytest.fixture
def hello(request):
@ -1376,7 +1375,7 @@ class TestFixtureManagerParseFactories:
assert faclist[0].func(item._request) == "conftest"
assert faclist[1].func(item._request) == "module"
assert faclist[2].func(item._request) == "class"
"""
"""
)
reprec = testdir.inline_run("-s")
reprec.assertoutcome(passed=1)

View File

@ -892,7 +892,7 @@ class TestMetafuncFunctional:
p = testdir.makepyfile(
"""
# assumes that generate/provide runs in the same process
import sys, pytest, six
import sys, pytest
def pytest_generate_tests(metafunc):
metafunc.parametrize('metafunc', [metafunc])
@ -910,7 +910,7 @@ class TestMetafuncFunctional:
def test_method(self, metafunc, pytestconfig):
assert metafunc.config == pytestconfig
assert metafunc.module.__name__ == __name__
unbound = six.get_unbound_function(TestClass.test_method)
unbound = TestClass.test_method
assert metafunc.function == unbound
assert metafunc.cls == TestClass
"""

View File

@ -917,7 +917,7 @@ def test_class_method_containing_test_issue1558(testdir):
@pytest.mark.parametrize(
"base", ["six.moves.builtins.object", "unittest.TestCase", "unittest2.TestCase"]
"base", ["builtins.object", "unittest.TestCase", "unittest2.TestCase"]
)
def test_usefixtures_marker_on_unittest(base, testdir):
"""#3498"""