From 4f735a66c5d12b00e16ba8a5907cee176af121a5 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Mon, 20 Jul 2009 18:54:18 +0200 Subject: [PATCH] improve unittest documentation, enable plugin by default --HG-- branch : 1.0.x --- py/test/defaultconftest.py | 2 +- py/test/plugin/pytest_unittest.py | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/py/test/defaultconftest.py b/py/test/defaultconftest.py index 6c7459df5..6ee22fb4e 100644 --- a/py/test/defaultconftest.py +++ b/py/test/defaultconftest.py @@ -10,5 +10,5 @@ Generator = py.test.collect.Generator Function = py.test.collect.Function Instance = py.test.collect.Instance -pytest_plugins = "default runner terminal keyword xfail tmpdir execnetcleanup monkeypatch recwarn pdb".split() +pytest_plugins = "default runner terminal keyword xfail tmpdir execnetcleanup monkeypatch recwarn pdb unittest".split() diff --git a/py/test/plugin/pytest_unittest.py b/py/test/plugin/pytest_unittest.py index a9916f24f..6e17a1c77 100644 --- a/py/test/plugin/pytest_unittest.py +++ b/py/test/plugin/pytest_unittest.py @@ -1,19 +1,24 @@ """ automatically discover and run traditional "unittest.py" style tests. -you can mix unittest TestCase subclasses and -py.test style tests in one test module. +Usage +---------------- -XXX consider user-specified test_suite() +This plugin collects and runs Python `unittest.py style`_ tests. +It will automatically collect ``unittest.TestCase`` subclasses +and their ``test`` methods from the test modules of a project +(usually following the ``test_*.py`` pattern). -this code is somewhat derived from Guido Wesdorps - - http://johnnydebris.net/svn/projects/py_unittest +This plugin is enabled by default. +.. _`unittest.py style`: http://docs.python.org/library/unittest.html """ import py +import sys def pytest_pycollect_makeitem(collector, name, obj): + if 'unittest' not in sys.modules: + return # nobody could have possibly derived a subclass if py.std.inspect.isclass(obj) and issubclass(obj, py.std.unittest.TestCase): return UnitTestCase(name, parent=collector)