streamline some hook docs and option handling, remove cruft bits, fix doc links
This commit is contained in:
parent
14b2b128c2
commit
5616874823
|
@ -261,7 +261,7 @@ reporting hooks
|
||||||
Collection related reporting hooks:
|
Collection related reporting hooks:
|
||||||
|
|
||||||
.. autofunction: pytest_collectstart
|
.. autofunction: pytest_collectstart
|
||||||
.. autofunction: pytest_log_itemcollect
|
.. autofunction: pytest_itemcollected
|
||||||
.. autofunction: pytest_collectreport
|
.. autofunction: pytest_collectreport
|
||||||
.. autofunction: pytest_deselected
|
.. autofunction: pytest_deselected
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
collect_ignore = ["nonpython"]
|
10
doc/faq.txt
10
doc/faq.txt
|
@ -16,9 +16,7 @@ more bug fixes and also works for Python3.
|
||||||
|
|
||||||
For Python2 you can also consult pip_ for the popular ``pip`` tool.
|
For Python2 you can also consult pip_ for the popular ``pip`` tool.
|
||||||
|
|
||||||
for the according ``pip`` installation tool. installation instructions.
|
However, If you want to install on Python3 you need to use Distribute_ which
|
||||||
You can also `setuptools`_ and
|
|
||||||
If you want to install on Python3 you need to use Distribute_ which
|
|
||||||
provides the ``easy_install`` utility.
|
provides the ``easy_install`` utility.
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,7 +66,6 @@ as a clone of ``py.test`` when py.test was in the ``0.8`` release
|
||||||
cycle so some of the newer features_ introduced with py.test-1.0
|
cycle so some of the newer features_ introduced with py.test-1.0
|
||||||
and py.test-1.1 have no counterpart in nose_.
|
and py.test-1.1 have no counterpart in nose_.
|
||||||
|
|
||||||
.. _nose: http://somethingaboutorange.com/mrl/projects/nose/0.11.1/
|
|
||||||
.. _features: test/features.html
|
.. _features: test/features.html
|
||||||
.. _apipkg: http://pypi.python.org/pypi/apipkg
|
.. _apipkg: http://pypi.python.org/pypi/apipkg
|
||||||
|
|
||||||
|
@ -111,8 +108,6 @@ in a managed class/module/function scope.
|
||||||
.. _monkeypatch: test/plugin/monkeypatch.html
|
.. _monkeypatch: test/plugin/monkeypatch.html
|
||||||
.. _tmpdir: test/plugin/tmpdir.html
|
.. _tmpdir: test/plugin/tmpdir.html
|
||||||
.. _capture: test/plugin/capture.html
|
.. _capture: test/plugin/capture.html
|
||||||
.. _`xUnit style setup`: test/xunit_setup.html
|
|
||||||
.. _`pytest_nose`: test/plugin/nose.html
|
|
||||||
|
|
||||||
.. _`why pytest_pyfuncarg__ methods?`:
|
.. _`why pytest_pyfuncarg__ methods?`:
|
||||||
|
|
||||||
|
@ -152,7 +147,6 @@ and implement the `parametrization scheme of your choice`_.
|
||||||
.. _`pytest_generate_tests`: test/funcargs.html#parametrizing-tests
|
.. _`pytest_generate_tests`: test/funcargs.html#parametrizing-tests
|
||||||
.. _`parametrization scheme of your choice`: http://tetamap.wordpress.com/2009/05/13/parametrizing-python-tests-generalized/
|
.. _`parametrization scheme of your choice`: http://tetamap.wordpress.com/2009/05/13/parametrizing-python-tests-generalized/
|
||||||
|
|
||||||
|
|
||||||
py.test interaction with other packages
|
py.test interaction with other packages
|
||||||
---------------------------------------------------
|
---------------------------------------------------
|
||||||
|
|
||||||
|
@ -185,4 +179,4 @@ script with this content and invoke that with the python version::
|
||||||
|
|
||||||
.. _`install distribute`: http://pypi.python.org/pypi/distribute#installation-instructions
|
.. _`install distribute`: http://pypi.python.org/pypi/distribute#installation-instructions
|
||||||
|
|
||||||
|
.. include:: links.inc
|
||||||
|
|
|
@ -4,12 +4,15 @@
|
||||||
# Initialization
|
# Initialization
|
||||||
# -------------------------------------------------------------------------
|
# -------------------------------------------------------------------------
|
||||||
|
|
||||||
|
def pytest_addhooks(pluginmanager):
|
||||||
|
"""called at plugin load time to allow adding new hooks via a call to
|
||||||
|
pluginmanager.registerhooks(module)."""
|
||||||
|
|
||||||
|
|
||||||
def pytest_namespace():
|
def pytest_namespace():
|
||||||
"""return dict of name->object to be made globally available in
|
"""return dict of name->object to be made globally available in
|
||||||
the py.test/pytest namespace. This hook is called before command
|
the py.test/pytest namespace. This hook is called before command
|
||||||
line options are fully parsed. If you want to provide helper functions
|
line options are parsed.
|
||||||
that can interact with a test function invocation, please refer to
|
|
||||||
:ref:`funcarg mechanism`.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def pytest_cmdline_parse(pluginmanager, args):
|
def pytest_cmdline_parse(pluginmanager, args):
|
||||||
|
@ -17,12 +20,9 @@ def pytest_cmdline_parse(pluginmanager, args):
|
||||||
pytest_cmdline_parse.firstresult = True
|
pytest_cmdline_parse.firstresult = True
|
||||||
|
|
||||||
def pytest_addoption(parser):
|
def pytest_addoption(parser):
|
||||||
"""allows to add optparse-style command line options via a call to
|
"""add optparse-style options and ini-style config values via calls
|
||||||
``parser.addoption(...)``."""
|
to ``parser.addoption`` and ``parser.addini(...)``.
|
||||||
|
"""
|
||||||
def pytest_addhooks(pluginmanager):
|
|
||||||
"""called at plugin load time to allow adding new hooks via a call to
|
|
||||||
pluginmanager.registerhooks(module)."""
|
|
||||||
|
|
||||||
def pytest_cmdline_main(config):
|
def pytest_cmdline_main(config):
|
||||||
""" called for performing the main command line action. The default
|
""" called for performing the main command line action. The default
|
||||||
|
@ -45,15 +45,16 @@ pytest_runtest_mainloop.firstresult = True
|
||||||
# collection hooks
|
# collection hooks
|
||||||
# -------------------------------------------------------------------------
|
# -------------------------------------------------------------------------
|
||||||
|
|
||||||
def pytest_perform_collection(session):
|
def pytest_collection_perform(session):
|
||||||
""" perform the collection protocol for the given session. """
|
""" perform the collection protocol for the given session. """
|
||||||
pytest_perform_collection.firstresult = True
|
pytest_collection_perform.firstresult = True
|
||||||
|
|
||||||
def pytest_collection_modifyitems(config, items):
|
def pytest_collection_modifyitems(config, items):
|
||||||
""" called to allow filtering and selecting of test items (inplace). """
|
""" called after collection has been performed, may filter or re-order
|
||||||
|
the items in-place."""
|
||||||
|
|
||||||
def pytest_log_finishcollection(collection):
|
def pytest_collection_finish(collection):
|
||||||
""" called after collection has finished. """
|
""" called after collection has been performed and modified. """
|
||||||
|
|
||||||
def pytest_ignore_collect(path, config):
|
def pytest_ignore_collect(path, config):
|
||||||
""" return True to prevent considering this path for collection.
|
""" return True to prevent considering this path for collection.
|
||||||
|
@ -75,7 +76,7 @@ def pytest_collect_file(path, parent):
|
||||||
def pytest_collectstart(collector):
|
def pytest_collectstart(collector):
|
||||||
""" collector starts collecting. """
|
""" collector starts collecting. """
|
||||||
|
|
||||||
def pytest_log_itemcollect(item):
|
def pytest_itemcollected(item):
|
||||||
""" we just collected a test item. """
|
""" we just collected a test item. """
|
||||||
|
|
||||||
def pytest_collectreport(report):
|
def pytest_collectreport(report):
|
||||||
|
@ -85,7 +86,7 @@ def pytest_deselected(items):
|
||||||
""" called for test items deselected by keyword. """
|
""" called for test items deselected by keyword. """
|
||||||
|
|
||||||
def pytest_make_collect_report(collector):
|
def pytest_make_collect_report(collector):
|
||||||
""" perform a collection and return a collection. """
|
""" perform ``collector.collect()`` and return a CollectReport. """
|
||||||
pytest_make_collect_report.firstresult = True
|
pytest_make_collect_report.firstresult = True
|
||||||
|
|
||||||
# -------------------------------------------------------------------------
|
# -------------------------------------------------------------------------
|
||||||
|
|
|
@ -155,7 +155,7 @@ class MarkInfo:
|
||||||
return "<MarkInfo %r args=%r kwargs=%r>" % (
|
return "<MarkInfo %r args=%r kwargs=%r>" % (
|
||||||
self._name, self.args, self.kwargs)
|
self._name, self.args, self.kwargs)
|
||||||
|
|
||||||
def pytest_log_itemcollect(item):
|
def pytest_itemcollected(item):
|
||||||
if not isinstance(item, py.test.collect.Function):
|
if not isinstance(item, py.test.collect.Function):
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -315,9 +315,7 @@ class FunctionMixin(PyobjMixin):
|
||||||
def repr_failure(self, excinfo, outerr=None):
|
def repr_failure(self, excinfo, outerr=None):
|
||||||
assert outerr is None, "XXX outerr usage is deprecated"
|
assert outerr is None, "XXX outerr usage is deprecated"
|
||||||
return self._repr_failure_py(excinfo,
|
return self._repr_failure_py(excinfo,
|
||||||
style=self.config.getvalue("tbstyle"))
|
style=self.config.option.tbstyle)
|
||||||
|
|
||||||
shortfailurerepr = "F"
|
|
||||||
|
|
||||||
class FuncargLookupErrorRepr(TerminalRepr):
|
class FuncargLookupErrorRepr(TerminalRepr):
|
||||||
def __init__(self, filename, firstlineno, deflines, errorstring):
|
def __init__(self, filename, firstlineno, deflines, errorstring):
|
||||||
|
|
|
@ -46,13 +46,13 @@ def pytest_configure(config):
|
||||||
def pytest_cmdline_main(config):
|
def pytest_cmdline_main(config):
|
||||||
return Session(config).main()
|
return Session(config).main()
|
||||||
|
|
||||||
def pytest_perform_collection(session):
|
def pytest_collection_perform(session):
|
||||||
collection = session.collection
|
collection = session.collection
|
||||||
assert not hasattr(collection, 'items')
|
assert not hasattr(collection, 'items')
|
||||||
hook = session.config.hook
|
hook = session.config.hook
|
||||||
collection.items = items = collection.perform_collect()
|
collection.items = items = collection.perform_collect()
|
||||||
hook.pytest_collection_modifyitems(config=session.config, items=items)
|
hook.pytest_collection_modifyitems(config=session.config, items=items)
|
||||||
hook.pytest_log_finishcollection(collection=collection)
|
hook.pytest_collection_finish(collection=collection)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def pytest_runtest_mainloop(session):
|
def pytest_runtest_mainloop(session):
|
||||||
|
@ -128,7 +128,7 @@ class Session(object):
|
||||||
try:
|
try:
|
||||||
config.pluginmanager.do_configure(config)
|
config.pluginmanager.do_configure(config)
|
||||||
config.hook.pytest_sessionstart(session=self)
|
config.hook.pytest_sessionstart(session=self)
|
||||||
config.hook.pytest_perform_collection(session=self)
|
config.hook.pytest_collection_perform(session=self)
|
||||||
config.hook.pytest_runtest_mainloop(session=self)
|
config.hook.pytest_runtest_mainloop(session=self)
|
||||||
except pytest.UsageError:
|
except pytest.UsageError:
|
||||||
raise
|
raise
|
||||||
|
@ -261,7 +261,7 @@ class Collection:
|
||||||
|
|
||||||
def genitems(self, node):
|
def genitems(self, node):
|
||||||
if isinstance(node, pytest.collect.Item):
|
if isinstance(node, pytest.collect.Item):
|
||||||
node.ihook.pytest_log_itemcollect(item=node)
|
node.ihook.pytest_itemcollected(item=node)
|
||||||
yield node
|
yield node
|
||||||
else:
|
else:
|
||||||
assert isinstance(node, pytest.collect.Collector)
|
assert isinstance(node, pytest.collect.Collector)
|
||||||
|
|
|
@ -213,7 +213,7 @@ def pytest_pyfunc_call(pyfuncitem):
|
||||||
check_xfail_no_run(pyfuncitem)
|
check_xfail_no_run(pyfuncitem)
|
||||||
|
|
||||||
def check_xfail_no_run(item):
|
def check_xfail_no_run(item):
|
||||||
if not item.config.getvalue("runxfail"):
|
if not item.config.option.runxfail:
|
||||||
evalxfail = item._evalxfail
|
evalxfail = item._evalxfail
|
||||||
if evalxfail.istrue():
|
if evalxfail.istrue():
|
||||||
if not evalxfail.get('run', True):
|
if not evalxfail.get('run', True):
|
||||||
|
|
|
@ -58,7 +58,7 @@ def pytest_unconfigure(config):
|
||||||
|
|
||||||
def getreportopt(config):
|
def getreportopt(config):
|
||||||
reportopts = ""
|
reportopts = ""
|
||||||
optvalue = config.getvalue("report")
|
optvalue = config.option.report
|
||||||
if optvalue:
|
if optvalue:
|
||||||
py.builtin.print_("DEPRECATED: use -r instead of --report option.",
|
py.builtin.print_("DEPRECATED: use -r instead of --report option.",
|
||||||
file=py.std.sys.stderr)
|
file=py.std.sys.stderr)
|
||||||
|
@ -69,7 +69,7 @@ def getreportopt(config):
|
||||||
reportopts += "s"
|
reportopts += "s"
|
||||||
elif setting == "xfailed":
|
elif setting == "xfailed":
|
||||||
reportopts += "x"
|
reportopts += "x"
|
||||||
reportchars = config.getvalue("reportchars")
|
reportchars = config.option.reportchars
|
||||||
if reportchars:
|
if reportchars:
|
||||||
for char in reportchars:
|
for char in reportchars:
|
||||||
if char not in reportopts:
|
if char not in reportopts:
|
||||||
|
@ -233,7 +233,7 @@ class TerminalReporter:
|
||||||
for line in flatten(lines):
|
for line in flatten(lines):
|
||||||
self.write_line(line)
|
self.write_line(line)
|
||||||
|
|
||||||
def pytest_log_finishcollection(self):
|
def pytest_collection_finish(self):
|
||||||
if not self.showheader:
|
if not self.showheader:
|
||||||
return
|
return
|
||||||
for i, testarg in enumerate(self.config.args):
|
for i, testarg in enumerate(self.config.args):
|
||||||
|
@ -259,7 +259,7 @@ class TerminalReporter:
|
||||||
msg = excrepr.reprcrash.message
|
msg = excrepr.reprcrash.message
|
||||||
self.write_sep("!", msg)
|
self.write_sep("!", msg)
|
||||||
if "KeyboardInterrupt" in msg:
|
if "KeyboardInterrupt" in msg:
|
||||||
if self.config.getvalue("fulltrace"):
|
if self.config.option.fulltrace:
|
||||||
excrepr.toterminal(self._tw)
|
excrepr.toterminal(self._tw)
|
||||||
else:
|
else:
|
||||||
excrepr.reprcrash.toterminal(self._tw)
|
excrepr.reprcrash.toterminal(self._tw)
|
||||||
|
@ -304,7 +304,7 @@ class TerminalReporter:
|
||||||
#
|
#
|
||||||
|
|
||||||
def summary_failures(self):
|
def summary_failures(self):
|
||||||
tbstyle = self.config.getvalue("tbstyle")
|
tbstyle = self.config.option.tbstyle
|
||||||
if 'failed' in self.stats and tbstyle != "no":
|
if 'failed' in self.stats and tbstyle != "no":
|
||||||
self.write_sep("=", "FAILURES")
|
self.write_sep("=", "FAILURES")
|
||||||
for rep in self.stats['failed']:
|
for rep in self.stats['failed']:
|
||||||
|
@ -379,7 +379,7 @@ class CollectonlyReporter:
|
||||||
self.outindent(collector)
|
self.outindent(collector)
|
||||||
self.indent += self.INDENT
|
self.indent += self.INDENT
|
||||||
|
|
||||||
def pytest_log_itemcollect(self, item):
|
def pytest_itemcollected(self, item):
|
||||||
self.outindent(item)
|
self.outindent(item)
|
||||||
|
|
||||||
def pytest_collectreport(self, report):
|
def pytest_collectreport(self, report):
|
||||||
|
@ -394,7 +394,7 @@ class CollectonlyReporter:
|
||||||
self._failed.append(report)
|
self._failed.append(report)
|
||||||
self.indent = self.indent[:-len(self.INDENT)]
|
self.indent = self.indent[:-len(self.INDENT)]
|
||||||
|
|
||||||
def pytest_log_finishcollection(self):
|
def pytest_collection_finish(self):
|
||||||
if self._failed:
|
if self._failed:
|
||||||
self._tw.sep("!", "collection failures")
|
self._tw.sep("!", "collection failures")
|
||||||
for rep in self._failed:
|
for rep in self._failed:
|
||||||
|
|
|
@ -21,7 +21,7 @@ class SessionTests:
|
||||||
assert failed[0].nodenames[-1] == "test_one_one"
|
assert failed[0].nodenames[-1] == "test_one_one"
|
||||||
assert failed[1].nodenames[-1] == "test_other"
|
assert failed[1].nodenames[-1] == "test_other"
|
||||||
assert failed[2].nodenames[-1] == "test_two"
|
assert failed[2].nodenames[-1] == "test_two"
|
||||||
itemstarted = reprec.getcalls("pytest_log_itemcollect")
|
itemstarted = reprec.getcalls("pytest_itemcollected")
|
||||||
assert len(itemstarted) == 4
|
assert len(itemstarted) == 4
|
||||||
colstarted = reprec.getcalls("pytest_collectstart")
|
colstarted = reprec.getcalls("pytest_collectstart")
|
||||||
assert len(colstarted) == 1 + 1 # XXX ExtraTopCollector
|
assert len(colstarted) == 1 + 1 # XXX ExtraTopCollector
|
||||||
|
@ -181,7 +181,7 @@ class TestNewSession(SessionTests):
|
||||||
)
|
)
|
||||||
reprec = testdir.inline_run('--collectonly', p.dirpath())
|
reprec = testdir.inline_run('--collectonly', p.dirpath())
|
||||||
|
|
||||||
itemstarted = reprec.getcalls("pytest_log_itemcollect")
|
itemstarted = reprec.getcalls("pytest_itemcollected")
|
||||||
assert len(itemstarted) == 3
|
assert len(itemstarted) == 3
|
||||||
assert not reprec.getreports("pytest_runtest_logreport")
|
assert not reprec.getreports("pytest_runtest_logreport")
|
||||||
started = reprec.getcalls("pytest_collectstart")
|
started = reprec.getcalls("pytest_collectstart")
|
||||||
|
|
|
@ -176,7 +176,7 @@ class TestCollectonly:
|
||||||
"<Module 'test_collectonly_basic.py'>"
|
"<Module 'test_collectonly_basic.py'>"
|
||||||
])
|
])
|
||||||
item = modcol.collect()[0]
|
item = modcol.collect()[0]
|
||||||
rep.config.hook.pytest_log_itemcollect(item=item)
|
rep.config.hook.pytest_itemcollected(item=item)
|
||||||
linecomp.assert_contains_lines([
|
linecomp.assert_contains_lines([
|
||||||
" <Function 'test_func'>",
|
" <Function 'test_func'>",
|
||||||
])
|
])
|
||||||
|
@ -456,24 +456,23 @@ def test_fail_reporting_on_pass(testdir):
|
||||||
assert 'short test summary' not in result.stdout.str()
|
assert 'short test summary' not in result.stdout.str()
|
||||||
|
|
||||||
def test_getreportopt():
|
def test_getreportopt():
|
||||||
testdict = {}
|
class config:
|
||||||
class Config:
|
class option:
|
||||||
def getvalue(self, name):
|
reportchars = ""
|
||||||
return testdict.get(name, None)
|
config.option.report = "xfailed"
|
||||||
config = Config()
|
|
||||||
testdict.update(dict(report="xfailed"))
|
|
||||||
assert getreportopt(config) == "x"
|
assert getreportopt(config) == "x"
|
||||||
|
|
||||||
testdict.update(dict(report="xfailed,skipped"))
|
config.option.report = "xfailed,skipped"
|
||||||
assert getreportopt(config) == "xs"
|
assert getreportopt(config) == "xs"
|
||||||
|
|
||||||
testdict.update(dict(report="skipped,xfailed"))
|
config.option.report = "skipped,xfailed"
|
||||||
assert getreportopt(config) == "sx"
|
assert getreportopt(config) == "sx"
|
||||||
|
|
||||||
testdict.update(dict(report="skipped", reportchars="sf"))
|
config.option.report = "skipped"
|
||||||
|
config.option.reportchars = "sf"
|
||||||
assert getreportopt(config) == "sf"
|
assert getreportopt(config) == "sf"
|
||||||
|
|
||||||
testdict.update(dict(reportchars="sfx"))
|
config.option.reportchars = "sfx"
|
||||||
assert getreportopt(config) == "sfx"
|
assert getreportopt(config) == "sfx"
|
||||||
|
|
||||||
def test_terminalreporter_reportopt_addargs(testdir):
|
def test_terminalreporter_reportopt_addargs(testdir):
|
||||||
|
|
Loading…
Reference in New Issue