Skip to content

Commit

Permalink
Merge pull request #3148 from nicoddemus/deprecate-old-style-classes-…
Browse files Browse the repository at this point in the history
…2147

All classes now subclass object for better py3 compatibility
  • Loading branch information
nicoddemus committed Jan 25, 2018
2 parents 2aad8c0 + af37778 commit b8be339
Show file tree
Hide file tree
Showing 22 changed files with 56 additions and 55 deletions.
2 changes: 1 addition & 1 deletion _pytest/_argcomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
from glob import glob


class FastFilesCompleter:
class FastFilesCompleter(object):
'Fast file completer class'

def __init__(self, directories=True):
Expand Down
2 changes: 1 addition & 1 deletion _pytest/assertion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def mark_rewrite(self, *names):
pass


class AssertionState:
class AssertionState(object):
"""State for the assertion plugin."""

def __init__(self, config, mode):
Expand Down
2 changes: 1 addition & 1 deletion _pytest/cacheprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def set(self, key, value):
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):
Expand Down
12 changes: 6 additions & 6 deletions _pytest/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def silence_logging_at_shutdown():
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -416,11 +416,11 @@ def readouterr(self):
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`
Expand Down Expand Up @@ -506,7 +506,7 @@ def snap(self):
return res


class SysCapture:
class SysCapture(object):
def __init__(self, fd, tmpfile=None):
name = patchsysdict[fd]
self._old = getattr(sys, name)
Expand Down Expand Up @@ -551,7 +551,7 @@ def snap(self):
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,
Expand Down
10 changes: 5 additions & 5 deletions _pytest/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def main(args=None, plugins=None):
return 4


class cmdline: # compatibility namespace
class cmdline(object): # compatibility namespace
main = staticmethod(main)


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -598,7 +598,7 @@ def __str__(self):
return self.msg


class Argument:
class Argument(object):
"""class that mimics the necessary behaviour of optparse.Option
its currently a least effort implementation
Expand Down Expand Up @@ -728,7 +728,7 @@ def __repr__(self):
return 'Argument({0})'.format(', '.join(args))


class OptionGroup:
class OptionGroup(object):
def __init__(self, name, description="", parser=None):
self.name = name
self.description = description
Expand Down Expand Up @@ -859,7 +859,7 @@ def copy(self):
return CmdOptions(self.__dict__)


class Notset:
class Notset(object):
def __repr__(self):
return "<NOTSET>"

Expand Down
4 changes: 2 additions & 2 deletions _pytest/debugging.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def fin():
config._cleanup.append(fin)


class pytestPDB:
class pytestPDB(object):
""" Pseudo PDB that defers to the real pdb. """
_pluginmanager = None
_config = None
Expand All @@ -62,7 +62,7 @@ def set_trace(cls):
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:
Expand Down
8 changes: 4 additions & 4 deletions _pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -443,7 +443,7 @@ def _get_active_fixturedef(self, argname):
fixturedef = self._getnextfixturedef(argname)
except FixtureLookupError:
if argname == "request":
class PseudoFixtureDef:
class PseudoFixtureDef(object):
cached_result = (self, [0], None)
scope = "function"
return PseudoFixtureDef
Expand Down Expand Up @@ -719,7 +719,7 @@ def teardown():
return res


class FixtureDef:
class FixtureDef(object):
""" A container for a factory definition. """

def __init__(self, fixturemanager, baseid, argname, func, scope, params,
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion _pytest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def find_module_patched(self, fullname, path=None):
yield


class FSHookProxy:
class FSHookProxy(object):
def __init__(self, fspath, pm, remove_mods):
self.fspath = fspath
self.pm = pm
Expand Down
2 changes: 1 addition & 1 deletion _pytest/mark.py
Original file line number Diff line number Diff line change
Expand Up @@ -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::
Expand Down
4 changes: 2 additions & 2 deletions _pytest/monkeypatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ def derive_importpath(import_path, raising):
return attr, target


class Notset:
class Notset(object):
def __repr__(self):
return "<notset>"


notset = Notset()


class MonkeyPatch:
class MonkeyPatch(object):
""" Object returned by the ``monkeypatch`` fixture keeping a record of setattr/item/env/syspath changes.
"""

Expand Down
28 changes: 14 additions & 14 deletions _pytest/pytester.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def _pytest(request):
return PytestArg(request)


class PytestArg:
class PytestArg(object):
def __init__(self, request):
self.request = request

Expand All @@ -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
Expand All @@ -197,7 +197,7 @@ def __repr__(self):
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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -397,15 +397,15 @@ def assert_outcomes(self, passed=0, skipped=0, failed=0, error=0):
assert obtained == dict(passed=passed, skipped=skipped, failed=failed, error=error)


class CwdSnapshot:
class CwdSnapshot(object):
def __init__(self):
self.__saved = os.getcwd()

def restore(self):
os.chdir(self.__saved)


class SysModulesSnapshot:
class SysModulesSnapshot(object):
def __init__(self, preserve=None):
self.__preserve = preserve
self.__saved = dict(sys.modules)
Expand All @@ -418,15 +418,15 @@ def restore(self):
sys.modules.update(self.__saved)


class SysPathsSnapshot:
class SysPathsSnapshot(object):
def __init__(self):
self.__saved = list(sys.path), list(sys.meta_path)

def restore(self):
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
Expand Down Expand Up @@ -740,7 +740,7 @@ def revert_warn_already_imported():

rec = []

class Collect:
class Collect(object):
def pytest_configure(x, config):
rec.append(self.make_hook_recorder(config.pluginmanager))

Expand All @@ -750,7 +750,7 @@ def pytest_configure(x, config):
if len(rec) == 1:
reprec = rec.pop()
else:
class reprec:
class reprec(object):
pass
reprec.ret = ret

Expand Down Expand Up @@ -780,13 +780,13 @@ def runpytest_inprocess(self, *args, **kwargs):
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()
Expand Down Expand Up @@ -1067,7 +1067,7 @@ def getdecoded(out):
py.io.saferepr(out),)


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

Expand All @@ -1085,7 +1085,7 @@ def assert_contains_lines(self, lines2):
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
Expand Down
2 changes: 1 addition & 1 deletion _pytest/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions _pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
"""
Expand Down Expand Up @@ -129,7 +129,7 @@ def get_location(self, config):
return None


class TerminalReporter:
class TerminalReporter(object):
def __init__(self, config, file=None):
import _pytest.config
self.config = config
Expand Down
2 changes: 1 addition & 1 deletion _pytest/tmpdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
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.
Expand Down
1 change: 1 addition & 0 deletions changelog/2147.removal
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion testing/acceptance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions testing/python/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,10 +880,10 @@ def test_issue2369_collect_module_fileext(self, testdir):
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()
Expand Down

0 comments on commit b8be339

Please sign in to comment.