* streamlining plugin docstrings

* better organisation of example directory, also does not break
  whole-test run anymore

--HG--
branch : 1.0.x
This commit is contained in:
holger krekel 2009-07-08 19:18:26 +02:00
parent 81d5e572ca
commit 8f0a85aee1
23 changed files with 106 additions and 39 deletions

View File

@ -1,9 +1,15 @@
Changes between 1.0.0b7 and 1.0.0b8 Changes between 1.0.0b7 and 1.0.0b8
===================================== =====================================
* docs: refined funcargs doc, use the term * if plugins use "py.test.importorskip" for importing
"factory" instead of "provider", added a new a dependency only a warning will be issued instead
talk/tutorial doc page of exiting the testing process.
* docs:
- refined funcargs doc , use the term "factory" instead
of "provider"
- added a new talk/tutorial doc page
- better plugin docstrings
* fixed teardown problem related to partially failing funcarg setups * fixed teardown problem related to partially failing funcarg setups
(thanks MrTopf for reporting), "pytest_runtest_teardown" is now (thanks MrTopf for reporting), "pytest_runtest_teardown" is now

View File

@ -33,7 +33,11 @@ doc/test/talks.txt
doc/test/test.txt doc/test/test.txt
doc/test/xunit_setup.txt doc/test/xunit_setup.txt
doc/xml.txt doc/xml.txt
example/assertion/failure_demo.py
example/assertion/test_failures.py
example/assertion/test_setup_flow_example.py
example/execnet/popen_read_multiple.py example/execnet/popen_read_multiple.py
example/funcarg/conftest.py
example/funcarg/costlysetup/conftest.py example/funcarg/costlysetup/conftest.py
example/funcarg/costlysetup/sub1/test_quick.py example/funcarg/costlysetup/sub1/test_quick.py
example/funcarg/costlysetup/sub2/test_two.py example/funcarg/costlysetup/sub2/test_two.py
@ -53,9 +57,6 @@ example/funcarg/test_simpleprovider.py
example/genhtml.py example/genhtml.py
example/genhtmlcss.py example/genhtmlcss.py
example/genxml.py example/genxml.py
example/pytest/failure_demo.py
example/pytest/test_failures.py
example/pytest/test_setup_flow_example.py
py/LICENSE py/LICENSE
py/__init__.py py/__init__.py
py/_com.py py/_com.py

View File

@ -9,6 +9,6 @@ def test_failure_demo_fails_properly(testdir):
passed, skipped, failed = reprec.countoutcomes() passed, skipped, failed = reprec.countoutcomes()
assert passed == 0 assert passed == 0
assert failed == 20, failed assert failed == 20, failed
colreports = reprec.getnamed("collectionreport") colreports = reprec.getreports("pytest_collectreport")
failed = len([x.failed for x in colreports]) failed = len([x.failed for x in colreports])
assert failed == 5 assert failed == 5

View File

@ -0,0 +1,3 @@
import py
collect_ignore = 'mysetup', 'mysetup2', 'test_simpleprovider.py', 'parametrize'

View File

@ -1,4 +1,4 @@
""" Plugin implementing defaults and general options. """ """ default hooks and general py.test options. """
import py import py
@ -115,7 +115,7 @@ def pytest_addoption(parser):
def pytest_configure(config): def pytest_configure(config):
fixoptions(config) fixoptions(config)
setsession(config) setsession(config)
loadplugins(config) #xxxloadplugins(config)
def fixoptions(config): def fixoptions(config):
if config.option.numprocesses: if config.option.numprocesses:
@ -124,7 +124,7 @@ def fixoptions(config):
if config.option.distload: if config.option.distload:
config.option.dist = "load" config.option.dist = "load"
def loadplugins(config): def xxxloadplugins(config):
for name in config.getvalue("plugin"): for name in config.getvalue("plugin"):
print "importing", name print "importing", name
config.pluginmanager.import_plugin(name) config.pluginmanager.import_plugin(name)

View File

@ -1,5 +1,5 @@
""" """
automatically collect and execute doctests. collect and execute doctests from modules and test files.
""" """
import py import py

View File

@ -1,5 +1,5 @@
""" """
cleanup gateways that were instantiated during a test function run. cleanup execnet gateways during test function runs.
""" """
import py import py

View File

@ -3,8 +3,7 @@ write and report coverage data using the 'figleaf' module.
""" """
import py import py
figleaf = py.test.importorskip("figleaf") figleaf = py.test.importorskip("figleaf.annote_html")
import figleaf.annotate_html
def pytest_addoption(parser): def pytest_addoption(parser):
group = parser.addgroup('figleaf options') group = parser.addgroup('figleaf options')

View File

@ -1,4 +1,4 @@
""" log calling of plugin hooks to a file. """ """ log invocations of extension hooks to a file. """
import py import py
def pytest_addoption(parser): def pytest_addoption(parser):

View File

@ -1,6 +1,5 @@
""" """
'capsys' and 'capfd' funcargs for capturing stdout/stderror either 'capsys' and 'capfd' funcargs for capturing stdout/stderror.
by intercepting sys.stdout/stderr or File Descriptors 1/2.
Calling the reset() method of the capture funcargs gives Calling the reset() method of the capture funcargs gives
a out/err tuple of strings representing the captured streams. a out/err tuple of strings representing the captured streams.

View File

@ -1,6 +1,5 @@
""" """
py.test.mark / keyword plugin py.test.mark / keyword plugin
""" """
import py import py

View File

@ -1,13 +1,13 @@
""" """
"monkeypatch" funcarg for safely patching objects, safely patch object attributes, dicts and environment variables.
dictionaries and environment variables during the execution of
a test. "monkeypatch" has three helper functions:
monkeypatch.setattr(obj, name, value) the "monkeypatch" funcarg has three helper functions:
monkeypatch.setitem(obj, name, value)
monkeypatch.setenv(name, value)
After the test has run modifications will be undone. monkeypatch.setattr(obj, name, value)
monkeypatch.setitem(obj, name, value)
monkeypatch.setenv(name, value)
After the test has run modifications will be undone.
""" """
import os import os

View File

@ -1,6 +1,5 @@
""" """
interactive debugging with a PDB prompt. interactive debugging with the Python Debugger.
""" """
import py import py
import pdb, sys, linecache import pdb, sys, linecache

View File

@ -1,5 +1,5 @@
""" """
py.test plugin for sending testing failure information to paste.pocoo.org submit failure information to paste.pocoo.org
""" """
import py import py

View File

@ -1,5 +1,5 @@
""" """
funcargs and support code for testing py.test functionality. funcargs and support code for testing py.test's own functionality.
""" """
import py import py

View File

@ -1,5 +1,5 @@
""" """
help performing checks for deprecation and other warnings. Provides: helpers for asserting deprecation and other warnings.
recwarn: function argument where one can call recwarn.pop() to get recwarn: function argument where one can call recwarn.pop() to get
the last warning that would have been shown. the last warning that would have been shown.

View File

@ -1,6 +1,5 @@
""" """
perform ReST specific tests on .txt files, including perform ReST syntax, local and remote reference tests on .rst/.txt files.
linkchecks and remote URL checks.
""" """
import py import py
@ -17,7 +16,7 @@ def pytest_addoption(parser):
help="force generation of html files.") help="force generation of html files.")
def pytest_collect_file(path, parent): def pytest_collect_file(path, parent):
if path.ext == ".txt": if path.ext in (".txt", ".rst"):
project = getproject(path) project = getproject(path)
if project is not None: if project is not None:
return ReSTFile(path, parent=parent, project=project) return ReSTFile(path, parent=parent, project=project)

View File

@ -1,5 +1,5 @@
""" """
collect and run test items and creating reports. collect and run test items and create reports.
""" """
import py import py

View File

@ -1,3 +1,6 @@
"""
terminal reporting of the full testing process.
"""
import py import py
import sys import sys

View File

@ -3,6 +3,7 @@ managing loading and interacting with pytest plugins.
""" """
import py import py
from py.__.test.plugin import hookspec from py.__.test.plugin import hookspec
from py.__.test.outcome import Skipped
def check_old_use(mod, modname): def check_old_use(mod, modname):
clsname = modname[len('pytest_'):].capitalize() + "Plugin" clsname = modname[len('pytest_'):].capitalize() + "Plugin"
@ -96,10 +97,20 @@ class PluginManager(object):
modname = canonical_importname(spec) modname = canonical_importname(spec)
if modname in self.impname2plugin: if modname in self.impname2plugin:
return return
mod = importplugin(modname) try:
check_old_use(mod, modname) mod = importplugin(modname)
self.register(mod) except KeyboardInterrupt:
self.consider_module(mod) raise
except Skipped, e:
self._warn("could not import plugin %r, reason: %r" %(
(modname, e.msg)))
else:
check_old_use(mod, modname)
self.register(mod)
self.consider_module(mod)
def _warn(self, msg):
print "===WARNING=== %s" % (msg,)
def _checkplugin(self, plugin): def _checkplugin(self, plugin):
# ===================================================== # =====================================================
@ -243,3 +254,36 @@ def formatdef(func):
py.std.inspect.formatargspec(*py.std.inspect.getargspec(func)) py.std.inspect.formatargspec(*py.std.inspect.getargspec(func))
) )
if __name__ == "__main__":
import py.__.test.plugin
basedir = py.path.local(py.__.test.plugin.__file__).dirpath()
name2text = {}
for p in basedir.listdir("pytest_*"):
if p.ext == ".py" or (
p.check(dir=1) and p.join("__init__.py").check()):
impname = p.purebasename
if impname.find("__") != -1:
continue
try:
plugin = importplugin(impname)
except (ImportError, py.__.test.outcome.Skipped):
name2text[impname] = "IMPORT ERROR"
else:
doc = plugin.__doc__ or ""
doc = doc.strip()
name2text[impname] = doc
for name in sorted(name2text.keys()):
text = name2text[name]
if name[0] == "_":
continue
print "%-20s %s" % (name, text.split("\n")[0])
#text = py.std.textwrap.wrap(name2text[name],
# width = 80,
# initial_indent="%s: " % name,
# replace_whitespace = False)
#for line in text:
# print line

View File

@ -7,12 +7,27 @@ class TestBootstrapping:
monkeypatch.setitem(os.environ, 'PYTEST_PLUGINS', 'nonexistingmodule') monkeypatch.setitem(os.environ, 'PYTEST_PLUGINS', 'nonexistingmodule')
py.test.raises(ImportError, "pluginmanager.consider_env()") py.test.raises(ImportError, "pluginmanager.consider_env()")
def test_preparse_args(self, monkeypatch): def test_preparse_args(self):
pluginmanager = PluginManager() pluginmanager = PluginManager()
py.test.raises(ImportError, """ py.test.raises(ImportError, """
pluginmanager.consider_preparse(["xyz", "-p", "hello123"]) pluginmanager.consider_preparse(["xyz", "-p", "hello123"])
""") """)
def test_plugin_skip(self, testdir, monkeypatch):
testdir.makepyfile(pytest_skipping1="""
import py
py.test.skip("hello")
""")
result = testdir.runpytest("-p", "skipping1")
result.stdout.fnmatch_lines([
"*WARNING*could not import plugin*skipping1*hello*"
])
monkeypatch.setenv("PYTEST_PLUGINS", "skipping1")
result = testdir.runpytest()
result.stdout.fnmatch_lines([
"*WARNING*could not import plugin*skipping1*hello*"
])
def test_consider_env_plugin_instantiation(self, testdir, monkeypatch): def test_consider_env_plugin_instantiation(self, testdir, monkeypatch):
pluginmanager = PluginManager() pluginmanager = PluginManager()
testdir.syspathinsert() testdir.syspathinsert()