parent
9bad9b53d8
commit
17a21d540b
|
@ -64,6 +64,7 @@ from glob import glob
|
||||||
|
|
||||||
class FastFilesCompleter:
|
class FastFilesCompleter:
|
||||||
'Fast file completer class'
|
'Fast file completer class'
|
||||||
|
|
||||||
def __init__(self, directories=True):
|
def __init__(self, directories=True):
|
||||||
self.directories = directories
|
self.directories = directories
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ else:
|
||||||
|
|
||||||
class Code(object):
|
class Code(object):
|
||||||
""" wrapper around Python code objects """
|
""" wrapper around Python code objects """
|
||||||
|
|
||||||
def __init__(self, rawcode):
|
def __init__(self, rawcode):
|
||||||
if not hasattr(rawcode, "co_filename"):
|
if not hasattr(rawcode, "co_filename"):
|
||||||
rawcode = getrawcode(rawcode)
|
rawcode = getrawcode(rawcode)
|
||||||
|
@ -260,6 +261,7 @@ class Traceback(list):
|
||||||
access to Traceback entries.
|
access to Traceback entries.
|
||||||
"""
|
"""
|
||||||
Entry = TracebackEntry
|
Entry = TracebackEntry
|
||||||
|
|
||||||
def __init__(self, tb, excinfo=None):
|
def __init__(self, tb, excinfo=None):
|
||||||
""" initialize from given python traceback object and ExceptionInfo """
|
""" initialize from given python traceback object and ExceptionInfo """
|
||||||
self._excinfo = excinfo
|
self._excinfo = excinfo
|
||||||
|
|
|
@ -19,6 +19,7 @@ class Source(object):
|
||||||
possibly deindenting it.
|
possibly deindenting it.
|
||||||
"""
|
"""
|
||||||
_compilecounter = 0
|
_compilecounter = 0
|
||||||
|
|
||||||
def __init__(self, *parts, **kwargs):
|
def __init__(self, *parts, **kwargs):
|
||||||
self.lines = lines = []
|
self.lines = lines = []
|
||||||
de = kwargs.get('deindent', True)
|
de = kwargs.get('deindent', True)
|
||||||
|
|
|
@ -89,6 +89,7 @@ class Cache(object):
|
||||||
|
|
||||||
class LFPlugin:
|
class LFPlugin:
|
||||||
""" Plugin which implements the --lf (run last-failing) option """
|
""" Plugin which implements the --lf (run last-failing) option """
|
||||||
|
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.config = config
|
self.config = config
|
||||||
active_keys = 'lf', 'failedfirst'
|
active_keys = 'lf', 'failedfirst'
|
||||||
|
|
|
@ -238,6 +238,7 @@ def safe_text_dupfile(f, mode, default_encoding="UTF8"):
|
||||||
|
|
||||||
class EncodedFile(object):
|
class EncodedFile(object):
|
||||||
errors = "strict" # possibly needed by py3 code (issue555)
|
errors = "strict" # possibly needed by py3 code (issue555)
|
||||||
|
|
||||||
def __init__(self, buffer, encoding):
|
def __init__(self, buffer, encoding):
|
||||||
self.buffer = buffer
|
self.buffer = buffer
|
||||||
self.encoding = encoding
|
self.encoding = encoding
|
||||||
|
|
|
@ -176,6 +176,7 @@ class PytestPluginManager(PluginManager):
|
||||||
``pytest_plugins`` global variables found in plugins being loaded;
|
``pytest_plugins`` global variables found in plugins being loaded;
|
||||||
* ``conftest.py`` loading during start-up;
|
* ``conftest.py`` loading during start-up;
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(PytestPluginManager, self).__init__("pytest", implprefix="pytest_")
|
super(PytestPluginManager, self).__init__("pytest", implprefix="pytest_")
|
||||||
self._conftest_plugins = set()
|
self._conftest_plugins = set()
|
||||||
|
@ -805,6 +806,7 @@ class DropShorterLongHelpFormatter(argparse.HelpFormatter):
|
||||||
- shortcut if there are only two options and one of them is a short one
|
- shortcut if there are only two options and one of them is a short one
|
||||||
- cache result on action object as this is called at least 2 times
|
- cache result on action object as this is called at least 2 times
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def _format_action_invocation(self, action):
|
def _format_action_invocation(self, action):
|
||||||
orgstr = argparse.HelpFormatter._format_action_invocation(self, action)
|
orgstr = argparse.HelpFormatter._format_action_invocation(self, action)
|
||||||
if orgstr and orgstr[0] != '-': # only optional arguments
|
if orgstr and orgstr[0] != '-': # only optional arguments
|
||||||
|
@ -854,10 +856,13 @@ def _ensure_removed_sysmodule(modname):
|
||||||
|
|
||||||
class CmdOptions(object):
|
class CmdOptions(object):
|
||||||
""" holds cmdline options as attributes."""
|
""" holds cmdline options as attributes."""
|
||||||
|
|
||||||
def __init__(self, values=()):
|
def __init__(self, values=()):
|
||||||
self.__dict__.update(values)
|
self.__dict__.update(values)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<CmdOptions %r>" % (self.__dict__,)
|
return "<CmdOptions %r>" % (self.__dict__,)
|
||||||
|
|
||||||
def copy(self):
|
def copy(self):
|
||||||
return CmdOptions(self.__dict__)
|
return CmdOptions(self.__dict__)
|
||||||
|
|
||||||
|
|
|
@ -559,6 +559,7 @@ class FixtureRequest(FuncargnamesCompatAttr):
|
||||||
class SubRequest(FixtureRequest):
|
class SubRequest(FixtureRequest):
|
||||||
""" a sub request for handling getting a fixture from a
|
""" a sub request for handling getting a fixture from a
|
||||||
test function/fixture. """
|
test function/fixture. """
|
||||||
|
|
||||||
def __init__(self, request, scope, param, param_index, fixturedef):
|
def __init__(self, request, scope, param, param_index, fixturedef):
|
||||||
self._parent_request = request
|
self._parent_request = request
|
||||||
self.fixturename = fixturedef.argname
|
self.fixturename = fixturedef.argname
|
||||||
|
@ -609,6 +610,7 @@ def scope2index(scope, descr, where=None):
|
||||||
|
|
||||||
class FixtureLookupError(LookupError):
|
class FixtureLookupError(LookupError):
|
||||||
""" could not return a requested Fixture (missing or invalid). """
|
""" could not return a requested Fixture (missing or invalid). """
|
||||||
|
|
||||||
def __init__(self, argname, request, msg=None):
|
def __init__(self, argname, request, msg=None):
|
||||||
self.argname = argname
|
self.argname = argname
|
||||||
self.request = request
|
self.request = request
|
||||||
|
@ -709,6 +711,7 @@ def call_fixture_func(fixturefunc, request, kwargs):
|
||||||
|
|
||||||
class FixtureDef:
|
class FixtureDef:
|
||||||
""" A container for a factory definition. """
|
""" A container for a factory definition. """
|
||||||
|
|
||||||
def __init__(self, fixturemanager, baseid, argname, func, scope, params,
|
def __init__(self, fixturemanager, baseid, argname, func, scope, params,
|
||||||
unittest=False, ids=None):
|
unittest=False, ids=None):
|
||||||
self._fixturemanager = fixturemanager
|
self._fixturemanager = fixturemanager
|
||||||
|
|
|
@ -155,6 +155,7 @@ def pytest_collection_modifyitems(items, config):
|
||||||
class MarkMapping:
|
class MarkMapping:
|
||||||
"""Provides a local mapping for markers where item access
|
"""Provides a local mapping for markers where item access
|
||||||
resolves to True if the marker is present. """
|
resolves to True if the marker is present. """
|
||||||
|
|
||||||
def __init__(self, keywords):
|
def __init__(self, keywords):
|
||||||
mymarks = set()
|
mymarks = set()
|
||||||
for key, value in keywords.items():
|
for key, value in keywords.items():
|
||||||
|
@ -170,6 +171,7 @@ class KeywordMapping:
|
||||||
"""Provides a local mapping for keywords.
|
"""Provides a local mapping for keywords.
|
||||||
Given a list of names, map any substring of one of these names to True.
|
Given a list of names, map any substring of one of these names to True.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, names):
|
def __init__(self, names):
|
||||||
self._names = names
|
self._names = names
|
||||||
|
|
||||||
|
@ -303,6 +305,7 @@ class MarkDecorator:
|
||||||
additional keyword or positional arguments.
|
additional keyword or positional arguments.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, mark):
|
def __init__(self, mark):
|
||||||
assert isinstance(mark, Mark), repr(mark)
|
assert isinstance(mark, Mark), repr(mark)
|
||||||
self.mark = mark
|
self.mark = mark
|
||||||
|
@ -366,6 +369,7 @@ class Mark(namedtuple('Mark', 'name, args, kwargs')):
|
||||||
|
|
||||||
class MarkInfo(object):
|
class MarkInfo(object):
|
||||||
""" Marking object created by :class:`MarkDecorator` instances. """
|
""" Marking object created by :class:`MarkDecorator` instances. """
|
||||||
|
|
||||||
def __init__(self, mark):
|
def __init__(self, mark):
|
||||||
assert isinstance(mark, Mark), repr(mark)
|
assert isinstance(mark, Mark), repr(mark)
|
||||||
self.combined = mark
|
self.combined = mark
|
||||||
|
|
|
@ -352,6 +352,7 @@ class RunResult:
|
||||||
:duration: Duration in seconds.
|
:duration: Duration in seconds.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, ret, outlines, errlines, duration):
|
def __init__(self, ret, outlines, errlines, duration):
|
||||||
self.ret = ret
|
self.ret = ret
|
||||||
self.outlines = outlines
|
self.outlines = outlines
|
||||||
|
@ -581,6 +582,7 @@ class Testdir:
|
||||||
return p
|
return p
|
||||||
|
|
||||||
Session = Session
|
Session = Session
|
||||||
|
|
||||||
def getnode(self, config, arg):
|
def getnode(self, config, arg):
|
||||||
"""Return the collection node of a file.
|
"""Return the collection node of a file.
|
||||||
|
|
||||||
|
|
|
@ -490,6 +490,7 @@ def _get_xunit_func(obj, name):
|
||||||
|
|
||||||
class Class(PyCollector):
|
class Class(PyCollector):
|
||||||
""" Collector for test methods. """
|
""" Collector for test methods. """
|
||||||
|
|
||||||
def collect(self):
|
def collect(self):
|
||||||
if not safe_getattr(self.obj, "__test__", True):
|
if not safe_getattr(self.obj, "__test__", True):
|
||||||
return []
|
return []
|
||||||
|
@ -715,6 +716,7 @@ class Metafunc(fixtures.FuncargnamesCompatAttr):
|
||||||
test configuration or values specified in the class or module where a
|
test configuration or values specified in the class or module where a
|
||||||
test function is defined.
|
test function is defined.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, function, fixtureinfo, config, cls=None, module=None):
|
def __init__(self, function, fixtureinfo, config, cls=None, module=None):
|
||||||
#: access to the :class:`_pytest.config.Config` object for the test session
|
#: access to the :class:`_pytest.config.Config` object for the test session
|
||||||
self.config = config
|
self.config = config
|
||||||
|
@ -1523,6 +1525,7 @@ class Function(FunctionMixin, main.Item, fixtures.FuncargnamesCompatAttr):
|
||||||
Python test function.
|
Python test function.
|
||||||
"""
|
"""
|
||||||
_genid = None
|
_genid = None
|
||||||
|
|
||||||
def __init__(self, name, parent, args=None, config=None,
|
def __init__(self, name, parent, args=None, config=None,
|
||||||
callspec=None, callobj=NOTSET, keywords=None, session=None,
|
callspec=None, callobj=NOTSET, keywords=None, session=None,
|
||||||
fixtureinfo=None, originalname=None):
|
fixtureinfo=None, originalname=None):
|
||||||
|
|
|
@ -148,6 +148,7 @@ class CallInfo:
|
||||||
""" Result/Exception info a function invocation. """
|
""" Result/Exception info a function invocation. """
|
||||||
#: None or ExceptionInfo object.
|
#: None or ExceptionInfo object.
|
||||||
excinfo = None
|
excinfo = None
|
||||||
|
|
||||||
def __init__(self, func, when):
|
def __init__(self, func, when):
|
||||||
#: context of invocation: one of "setup", "call",
|
#: context of invocation: one of "setup", "call",
|
||||||
#: "teardown", "memocollect"
|
#: "teardown", "memocollect"
|
||||||
|
@ -277,6 +278,7 @@ class TestReport(BaseReport):
|
||||||
""" Basic test report object (also used for setup and teardown calls if
|
""" Basic test report object (also used for setup and teardown calls if
|
||||||
they fail).
|
they fail).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, nodeid, location, keywords, outcome,
|
def __init__(self, nodeid, location, keywords, outcome,
|
||||||
longrepr, when, sections=(), duration=0, **extra):
|
longrepr, when, sections=(), duration=0, **extra):
|
||||||
#: normalized collection node id
|
#: normalized collection node id
|
||||||
|
@ -318,6 +320,7 @@ class TestReport(BaseReport):
|
||||||
class TeardownErrorReport(BaseReport):
|
class TeardownErrorReport(BaseReport):
|
||||||
outcome = "failed"
|
outcome = "failed"
|
||||||
when = "teardown"
|
when = "teardown"
|
||||||
|
|
||||||
def __init__(self, longrepr, **extra):
|
def __init__(self, longrepr, **extra):
|
||||||
self.longrepr = longrepr
|
self.longrepr = longrepr
|
||||||
self.sections = []
|
self.sections = []
|
||||||
|
@ -370,11 +373,13 @@ class CollectReport(BaseReport):
|
||||||
class CollectErrorRepr(TerminalRepr):
|
class CollectErrorRepr(TerminalRepr):
|
||||||
def __init__(self, msg):
|
def __init__(self, msg):
|
||||||
self.longrepr = msg
|
self.longrepr = msg
|
||||||
|
|
||||||
def toterminal(self, out):
|
def toterminal(self, out):
|
||||||
out.line(self.longrepr, red=True)
|
out.line(self.longrepr, red=True)
|
||||||
|
|
||||||
class SetupState(object):
|
class SetupState(object):
|
||||||
""" shared state for setting up/tearing down test items or collectors. """
|
""" shared state for setting up/tearing down test items or collectors. """
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.stack = []
|
self.stack = []
|
||||||
self._finalizers = {}
|
self._finalizers = {}
|
||||||
|
@ -469,6 +474,7 @@ class OutcomeException(Exception):
|
||||||
""" OutcomeException and its subclass instances indicate and
|
""" OutcomeException and its subclass instances indicate and
|
||||||
contain info about test and collection outcomes.
|
contain info about test and collection outcomes.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, msg=None, pytrace=True):
|
def __init__(self, msg=None, pytrace=True):
|
||||||
Exception.__init__(self, msg)
|
Exception.__init__(self, msg)
|
||||||
self.msg = msg
|
self.msg = msg
|
||||||
|
@ -500,6 +506,7 @@ class Failed(OutcomeException):
|
||||||
|
|
||||||
class Exit(KeyboardInterrupt):
|
class Exit(KeyboardInterrupt):
|
||||||
""" raised for immediate program exits (no tracebacks/summaries)"""
|
""" raised for immediate program exits (no tracebacks/summaries)"""
|
||||||
|
|
||||||
def __init__(self, msg="unknown reason"):
|
def __init__(self, msg="unknown reason"):
|
||||||
self.msg = msg
|
self.msg = msg
|
||||||
KeyboardInterrupt.__init__(self, msg)
|
KeyboardInterrupt.__init__(self, msg)
|
||||||
|
|
|
@ -88,6 +88,7 @@ class WarningReport:
|
||||||
"""
|
"""
|
||||||
Simple structure to hold warnings information captured by ``pytest_logwarning``.
|
Simple structure to hold warnings information captured by ``pytest_logwarning``.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, code, message, nodeid=None, fslocation=None):
|
def __init__(self, code, message, nodeid=None, fslocation=None):
|
||||||
"""
|
"""
|
||||||
:param code: unused
|
:param code: unused
|
||||||
|
|
|
@ -764,6 +764,7 @@ class TestDurationWithFixture(object):
|
||||||
def test_2():
|
def test_2():
|
||||||
time.sleep(frag)
|
time.sleep(frag)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def test_setup_function(self, testdir):
|
def test_setup_function(self, testdir):
|
||||||
testdir.makepyfile(self.source)
|
testdir.makepyfile(self.source)
|
||||||
result = testdir.runpytest("--durations=10")
|
result = testdir.runpytest("--durations=10")
|
||||||
|
|
|
@ -33,14 +33,19 @@ class TWMock(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.lines = []
|
self.lines = []
|
||||||
self.is_writing = False
|
self.is_writing = False
|
||||||
|
|
||||||
def sep(self, sep, line=None):
|
def sep(self, sep, line=None):
|
||||||
self.lines.append((sep, line))
|
self.lines.append((sep, line))
|
||||||
|
|
||||||
def write(self, msg, **kw):
|
def write(self, msg, **kw):
|
||||||
self.lines.append((TWMock.WRITE, msg))
|
self.lines.append((TWMock.WRITE, msg))
|
||||||
|
|
||||||
def line(self, line, **kw):
|
def line(self, line, **kw):
|
||||||
self.lines.append(line)
|
self.lines.append(line)
|
||||||
|
|
||||||
def markup(self, text, **kw):
|
def markup(self, text, **kw):
|
||||||
return text
|
return text
|
||||||
|
|
||||||
def get_write_msg(self, idx):
|
def get_write_msg(self, idx):
|
||||||
flag, msg = self.lines[idx]
|
flag, msg = self.lines[idx]
|
||||||
assert flag == TWMock.WRITE
|
assert flag == TWMock.WRITE
|
||||||
|
|
|
@ -127,6 +127,7 @@ class TestAccesses(object):
|
||||||
def g(x):
|
def g(x):
|
||||||
pass
|
pass
|
||||||
""")
|
""")
|
||||||
|
|
||||||
def test_getrange(self):
|
def test_getrange(self):
|
||||||
x = self.source[0:2]
|
x = self.source[0:2]
|
||||||
assert x.isparseable()
|
assert x.isparseable()
|
||||||
|
|
|
@ -1251,6 +1251,7 @@ class TestMetafuncFunctionalAuto(object):
|
||||||
|
|
||||||
class TestMarkersWithParametrization(object):
|
class TestMarkersWithParametrization(object):
|
||||||
pytestmark = pytest.mark.issue308
|
pytestmark = pytest.mark.issue308
|
||||||
|
|
||||||
def test_simple_mark(self, testdir):
|
def test_simple_mark(self, testdir):
|
||||||
s = """
|
s = """
|
||||||
import pytest
|
import pytest
|
||||||
|
|
|
@ -38,6 +38,7 @@ def _wrapcall(*args, **kargs):
|
||||||
|
|
||||||
class FilesCompleter(object):
|
class FilesCompleter(object):
|
||||||
'File completer class, optionally takes a list of allowed extensions'
|
'File completer class, optionally takes a list of allowed extensions'
|
||||||
|
|
||||||
def __init__(self, allowednames=(), directories=True):
|
def __init__(self, allowednames=(), directories=True):
|
||||||
# Fix if someone passes in a string instead of a list
|
# Fix if someone passes in a string instead of a list
|
||||||
if type(allowednames) is str:
|
if type(allowednames) is str:
|
||||||
|
|
|
@ -78,6 +78,7 @@ def make_holder():
|
||||||
class apiclass(object):
|
class apiclass(object):
|
||||||
def pytest_xyz(self, arg):
|
def pytest_xyz(self, arg):
|
||||||
"x"
|
"x"
|
||||||
|
|
||||||
def pytest_xyz_noarg(self):
|
def pytest_xyz_noarg(self):
|
||||||
"x"
|
"x"
|
||||||
|
|
||||||
|
|
|
@ -697,6 +697,7 @@ class TestGenericReporting(object):
|
||||||
""" this test class can be subclassed with a different option
|
""" this test class can be subclassed with a different option
|
||||||
provider to run e.g. distributed tests.
|
provider to run e.g. distributed tests.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def test_collect_fail(self, testdir, option):
|
def test_collect_fail(self, testdir, option):
|
||||||
testdir.makepyfile("import xyz\n")
|
testdir.makepyfile("import xyz\n")
|
||||||
result = testdir.runpytest(*option.args)
|
result = testdir.runpytest(*option.args)
|
||||||
|
|
2
tox.ini
2
tox.ini
|
@ -196,6 +196,6 @@ filterwarnings =
|
||||||
ignore:.*inspect.getargspec.*deprecated, use inspect.signature.*:DeprecationWarning
|
ignore:.*inspect.getargspec.*deprecated, use inspect.signature.*:DeprecationWarning
|
||||||
|
|
||||||
[flake8]
|
[flake8]
|
||||||
ignore = E301,E302,E303,E401,E402,E501,E701,E702,E704,E712,E731
|
ignore = E302,E303,E401,E402,E501,E701,E702,E704,E712,E731
|
||||||
max-line-length = 120
|
max-line-length = 120
|
||||||
exclude = _pytest/vendored_packages/pluggy.py
|
exclude = _pytest/vendored_packages/pluggy.py
|
||||||
|
|
Loading…
Reference in New Issue