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 # remove _width_of_current_line in terminal.py
INSTALL_REQUIRES = [ INSTALL_REQUIRES = [
"py>=1.5.0", "py>=1.5.0",
"six>=1.10.0",
"packaging", "packaging",
"attrs>=17.4.0", "attrs>=17.4.0",
"more-itertools>=4.0.0", "more-itertools>=4.0.0",

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,9 +1,7 @@
import logging import logging
import py.io import py.io
import six
import pytest
from _pytest.logging import ColoredLevelFormatter from _pytest.logging import ColoredLevelFormatter
@ -38,9 +36,6 @@ def test_coloredlogformatter():
assert output == ("dummypath 10 INFO Test Message") 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(): def test_multiline_message():
from _pytest.logging import PercentStyleMultiline from _pytest.logging import PercentStyleMultiline

View File

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

View File

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

View File

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

View File

@ -917,7 +917,7 @@ def test_class_method_containing_test_issue1558(testdir):
@pytest.mark.parametrize( @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): def test_usefixtures_marker_on_unittest(base, testdir):
"""#3498""" """#3498"""