All classes now subclass object for better py3 compatibility

Fix #2147
This commit is contained in:
Bruno Oliveira 2018-01-24 18:23:42 -02:00
parent 3b3d237f07
commit af37778b0d
22 changed files with 56 additions and 55 deletions

View File

@ -60,7 +60,7 @@ import os
from glob import glob
class FastFilesCompleter:
class FastFilesCompleter(object):
'Fast file completer class'
def __init__(self, directories=True):

View File

@ -56,7 +56,7 @@ class DummyRewriteHook(object):
pass
class AssertionState:
class AssertionState(object):
"""State for the assertion plugin."""
def __init__(self, config, mode):

View File

@ -98,7 +98,7 @@ class Cache(object):
json.dump(value, f, indent=2, sort_keys=True)
class LFPlugin:
class LFPlugin(object):
""" Plugin which implements the --lf (run last-failing) option """
def __init__(self, config):

View File

@ -61,7 +61,7 @@ def pytest_load_initial_conftests(early_config, parser, args):
sys.stderr.write(err)
class CaptureManager:
class CaptureManager(object):
"""
Capture plugin, manages that the appropriate capture method is enabled/disabled during collection and each
test phase (setup, call, teardown). After each of those points, the captured output is obtained and
@ -271,7 +271,7 @@ def _install_capture_fixture_on_item(request, capture_class):
del request.node._capture_fixture
class CaptureFixture:
class CaptureFixture(object):
def __init__(self, captureclass, request):
self.captureclass = captureclass
self.request = request
@ -416,11 +416,11 @@ class MultiCapture(object):
self.err.snap() if self.err is not None else "")
class NoCapture:
class NoCapture(object):
__init__ = start = done = suspend = resume = lambda *args: None
class FDCaptureBinary:
class FDCaptureBinary(object):
"""Capture IO to/from a given os-level filedescriptor.
snap() produces `bytes`
@ -506,7 +506,7 @@ class FDCapture(FDCaptureBinary):
return res
class SysCapture:
class SysCapture(object):
def __init__(self, fd, tmpfile=None):
name = patchsysdict[fd]
self._old = getattr(sys, name)
@ -551,7 +551,7 @@ class SysCaptureBinary(SysCapture):
return res
class DontReadFromInput:
class DontReadFromInput(object):
"""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,

View File

@ -66,7 +66,7 @@ def main(args=None, plugins=None):
return 4
class cmdline: # compatibility namespace
class cmdline(object): # compatibility namespace
main = staticmethod(main)
@ -463,7 +463,7 @@ def _get_plugin_specs_as_list(specs):
return []
class Parser:
class Parser(object):
""" Parser for command line arguments and ini-file values.
:ivar extra_info: dict of generic param -> value to display in case
@ -598,7 +598,7 @@ class ArgumentError(Exception):
return self.msg
class Argument:
class Argument(object):
"""class that mimics the necessary behaviour of optparse.Option
its currently a least effort implementation
@ -728,7 +728,7 @@ class Argument:
return 'Argument({0})'.format(', '.join(args))
class OptionGroup:
class OptionGroup(object):
def __init__(self, name, description="", parser=None):
self.name = name
self.description = description
@ -859,7 +859,7 @@ class CmdOptions(object):
return CmdOptions(self.__dict__)
class Notset:
class Notset(object):
def __repr__(self):
return "<NOTSET>"

View File

@ -40,7 +40,7 @@ def pytest_configure(config):
config._cleanup.append(fin)
class pytestPDB:
class pytestPDB(object):
""" Pseudo PDB that defers to the real pdb. """
_pluginmanager = None
_config = None
@ -62,7 +62,7 @@ class pytestPDB:
cls._pdb_cls().set_trace(frame)
class PdbInvoke:
class PdbInvoke(object):
def pytest_exception_interact(self, node, call, report):
capman = node.config.pluginmanager.getplugin("capturemanager")
if capman:

View File

@ -247,7 +247,7 @@ def get_direct_param_fixture_func(request):
return request.param
class FuncFixtureInfo:
class FuncFixtureInfo(object):
def __init__(self, argnames, names_closure, name2fixturedefs):
self.argnames = argnames
self.names_closure = names_closure
@ -443,7 +443,7 @@ class FixtureRequest(FuncargnamesCompatAttr):
fixturedef = self._getnextfixturedef(argname)
except FixtureLookupError:
if argname == "request":
class PseudoFixtureDef:
class PseudoFixtureDef(object):
cached_result = (self, [0], None)
scope = "function"
return PseudoFixtureDef
@ -719,7 +719,7 @@ def call_fixture_func(fixturefunc, request, kwargs):
return res
class FixtureDef:
class FixtureDef(object):
""" A container for a factory definition. """
def __init__(self, fixturemanager, baseid, argname, func, scope, params,
@ -925,7 +925,7 @@ def pytestconfig(request):
return request.config
class FixtureManager:
class FixtureManager(object):
"""
pytest fixtures definitions and information is stored and managed
from this class.

View File

@ -243,7 +243,7 @@ def _patched_find_module():
yield
class FSHookProxy:
class FSHookProxy(object):
def __init__(self, fspath, pm, remove_mods):
self.fspath = fspath
self.pm = pm

View File

@ -284,7 +284,7 @@ def pytest_unconfigure(config):
MARK_GEN._config = getattr(config, '_old_mark_config', None)
class MarkGenerator:
class MarkGenerator(object):
""" Factory for :class:`MarkDecorator` objects - exposed as
a ``pytest.mark`` singleton instance. Example::

View File

@ -88,7 +88,7 @@ def derive_importpath(import_path, raising):
return attr, target
class Notset:
class Notset(object):
def __repr__(self):
return "<notset>"
@ -96,7 +96,7 @@ class Notset:
notset = Notset()
class MonkeyPatch:
class MonkeyPatch(object):
""" Object returned by the ``monkeypatch`` fixture keeping a record of setattr/item/env/syspath changes.
"""

View File

@ -171,7 +171,7 @@ def _pytest(request):
return PytestArg(request)
class PytestArg:
class PytestArg(object):
def __init__(self, request):
self.request = request
@ -186,7 +186,7 @@ def get_public_names(values):
return [x for x in values if x[0] != "_"]
class ParsedCall:
class ParsedCall(object):
def __init__(self, name, kwargs):
self.__dict__.update(kwargs)
self._name = name
@ -197,7 +197,7 @@ class ParsedCall:
return "<ParsedCall %r(**%r)>" % (self._name, d)
class HookRecorder:
class HookRecorder(object):
"""Record all hooks called in a plugin manager.
This wraps all the hook calls in the plugin manager, recording each call
@ -343,7 +343,7 @@ def testdir(request, tmpdir_factory):
rex_outcome = re.compile(r"(\d+) ([\w-]+)")
class RunResult:
class RunResult(object):
"""The result of running a command.
Attributes:
@ -397,7 +397,7 @@ class RunResult:
assert obtained == dict(passed=passed, skipped=skipped, failed=failed, error=error)
class CwdSnapshot:
class CwdSnapshot(object):
def __init__(self):
self.__saved = os.getcwd()
@ -405,7 +405,7 @@ class CwdSnapshot:
os.chdir(self.__saved)
class SysModulesSnapshot:
class SysModulesSnapshot(object):
def __init__(self, preserve=None):
self.__preserve = preserve
self.__saved = dict(sys.modules)
@ -418,7 +418,7 @@ class SysModulesSnapshot:
sys.modules.update(self.__saved)
class SysPathsSnapshot:
class SysPathsSnapshot(object):
def __init__(self):
self.__saved = list(sys.path), list(sys.meta_path)
@ -426,7 +426,7 @@ class SysPathsSnapshot:
sys.path[:], sys.meta_path[:] = self.__saved
class Testdir:
class Testdir(object):
"""Temporary test directory with tools to test/run pytest itself.
This is based on the ``tmpdir`` fixture but provides a number of methods
@ -740,7 +740,7 @@ class Testdir:
rec = []
class Collect:
class Collect(object):
def pytest_configure(x, config):
rec.append(self.make_hook_recorder(config.pluginmanager))
@ -750,7 +750,7 @@ class Testdir:
if len(rec) == 1:
reprec = rec.pop()
else:
class reprec:
class reprec(object):
pass
reprec.ret = ret
@ -780,13 +780,13 @@ class Testdir:
reprec = self.inline_run(*args, **kwargs)
except SystemExit as e:
class reprec:
class reprec(object):
ret = e.args[0]
except Exception:
traceback.print_exc()
class reprec:
class reprec(object):
ret = 3
finally:
out, err = capture.readouterr()
@ -1067,7 +1067,7 @@ def getdecoded(out):
py.io.saferepr(out),)
class LineComp:
class LineComp(object):
def __init__(self):
self.stringio = py.io.TextIO()
@ -1085,7 +1085,7 @@ class LineComp:
return LineMatcher(lines1).fnmatch_lines(lines2)
class LineMatcher:
class LineMatcher(object):
"""Flexible matching of text.
This is a convenience class to test large texts like the output of

View File

@ -178,7 +178,7 @@ def call_runtest_hook(item, when, **kwds):
return CallInfo(lambda: ihook(item=item, **kwds), when=when)
class CallInfo:
class CallInfo(object):
""" Result/Exception info a function invocation. """
#: None or ExceptionInfo object.
excinfo = None

View File

@ -94,7 +94,7 @@ def pytest_report_teststatus(report):
return report.outcome, letter, report.outcome.upper()
class WarningReport:
class WarningReport(object):
"""
Simple structure to hold warnings information captured by ``pytest_logwarning``.
"""
@ -129,7 +129,7 @@ class WarningReport:
return None
class TerminalReporter:
class TerminalReporter(object):
def __init__(self, config, file=None):
import _pytest.config
self.config = config

View File

@ -8,7 +8,7 @@ import py
from _pytest.monkeypatch import MonkeyPatch
class TempdirFactory:
class TempdirFactory(object):
"""Factory for temporary directories under the common base temp directory.
The base directory can be configured using the ``--basetemp`` option.

1
changelog/2147.removal Normal file
View File

@ -0,0 +1 @@
All pytest classes now subclass ``object`` for better Python 3 compatibility. This should not affect user code except in very rare edge cases.

View File

@ -901,7 +901,7 @@ def test_deferred_hook_checking(testdir):
testdir.syspathinsert()
testdir.makepyfile(**{
'plugin.py': """
class Hooks:
class Hooks(object):
def pytest_my_hook(self, config):
pass

View File

@ -880,10 +880,10 @@ class TestConftestCustomization(object):
import sys, os, imp
from _pytest.python import Module
class Loader:
class Loader(object):
def load_module(self, name):
return imp.load_source(name, name + ".narf")
class Finder:
class Finder(object):
def find_module(self, name, path=None):
if os.path.exists(name + ".narf"):
return Loader()

View File

@ -2828,7 +2828,7 @@ class TestShowFixtures(object):
def test_show_fixtures_indented_in_class(self, testdir):
p = testdir.makepyfile(dedent('''
import pytest
class TestClass:
class TestClass(object):
@pytest.fixture
def fixture1(self):
"""line1

View File

@ -241,7 +241,7 @@ class TestMetafunc(object):
"""
from _pytest.python import _idval
class TestClass:
class TestClass(object):
pass
def test_function():

View File

@ -1245,7 +1245,7 @@ def test_py36_windowsconsoleio_workaround_non_standard_streams():
"""
from _pytest.capture import _py36_windowsconsoleio_workaround
class DummyStream:
class DummyStream(object):
def write(self, s):
pass

View File

@ -135,7 +135,7 @@ def test_makepyfile_utf8(testdir):
assert u"mixed_encoding = u'São Paulo'".encode('utf-8') in p.read('rb')
class TestInlineRunModulesCleanup:
class TestInlineRunModulesCleanup(object):
def test_inline_run_test_module_not_cleaned_up(self, testdir):
test_mod = testdir.makepyfile("def test_foo(): assert True")
result = testdir.inline_run(str(test_mod))
@ -146,7 +146,7 @@ class TestInlineRunModulesCleanup:
assert result2.ret == EXIT_TESTSFAILED
def spy_factory(self):
class SysModulesSnapshotSpy:
class SysModulesSnapshotSpy(object):
instances = []
def __init__(self, preserve=None):
@ -223,7 +223,7 @@ def test_inline_run_clean_sys_paths(testdir):
assert sys.meta_path == original_meta_path
def spy_factory(self):
class SysPathsSnapshotSpy:
class SysPathsSnapshotSpy(object):
instances = []
def __init__(self):
@ -266,7 +266,7 @@ def test_cwd_snapshot(tmpdir):
assert py.path.local() == foo
class TestSysModulesSnapshot:
class TestSysModulesSnapshot(object):
key = 'my-test-module'
def test_remove_added(self):
@ -329,7 +329,7 @@ class TestSysModulesSnapshot:
@pytest.mark.parametrize('path_type', ('path', 'meta_path'))
class TestSysPathsSnapshot:
class TestSysPathsSnapshot(object):
other_path = {
'path': 'meta_path',
'meta_path': 'path'}

View File

@ -966,7 +966,7 @@ def test_no_trailing_whitespace_after_inifile_word(testdir):
assert 'inifile: tox.ini\n' in result.stdout.str()
class TestProgress:
class TestProgress(object):
@pytest.fixture
def many_tests_files(self, testdir):
@ -1047,7 +1047,7 @@ class TestProgress:
])
class TestProgressWithTeardown:
class TestProgressWithTeardown(object):
"""Ensure we show the correct percentages for tests that fail during teardown (#3088)"""
@pytest.fixture