[py-svn] r61698 - in py/branch/pytestplugin/py/test: plugin testing
hpk at codespeak.net
hpk at codespeak.net
Tue Feb 10 17:07:05 CET 2009
Author: hpk
Date: Tue Feb 10 17:07:05 2009
New Revision: 61698
Modified:
py/branch/pytestplugin/py/test/plugin/pytest_pytester.py
py/branch/pytestplugin/py/test/testing/test_collect.py
Log:
using the plugin-provided per-method tmpdir
Modified: py/branch/pytestplugin/py/test/plugin/pytest_pytester.py
==============================================================================
--- py/branch/pytestplugin/py/test/plugin/pytest_pytester.py (original)
+++ py/branch/pytestplugin/py/test/plugin/pytest_pytester.py Tue Feb 10 17:07:05 2009
@@ -35,6 +35,9 @@
if not impname in self._plugins:
self._plugins.append(impname)
+ def parseconfig(self, *args):
+ return py.test.config._reparse(list(args))
+
def _writeconftest(self):
p = self.tmpdir.join("conftest.py")
pstring = repr(self._plugins)
@@ -148,24 +151,26 @@
self.fstester = FSTester(self.tmpdir)
#self.capture = py.io.StdCapture()
+ def parseconfig(self, *args):
+ return py.test.config._reparse(list(args))
+
#def finalize(self):
# self.capture.reset()
#
def genitems(self, colitems):
return self.session.genitems(colitems)
- def parseconfig(self, *args):
- return py.test.config._reparse(list(args))
-
def getitem(self, source, funcname="test_func"):
modcol = self.getmodulecol(source)
item = modcol.join(funcname)
assert item is not None, "%r item not found in module:\n%s" %(funcname, source)
return item
- def getmodulecol(self, source, configargs=(), withsession=False):
+ def getmodulecol(self, source, configargs=(), withinit=False):
kw = {self.pyfuncitem.name: py.code.Source(source).strip()}
path = self.fstester.makepyfile(**kw)
+ if withinit:
+ self.fstester.makepyfile(__init__ = "#")
self.config = self.parseconfig(path, *configargs)
self.session = self.config.initsession()
return self.config.getfsnode(path)
@@ -177,3 +182,7 @@
elif argname == "tsession":
tsession = TSession(pyfuncitem)
return tsession, None
+ elif argname == "fstester":
+ tmpdir = py.test.ensuretemp("_".join(pyfuncitem.listnames()))
+ fstester = FSTester(tmpdir)
+ return fstester, None
Modified: py/branch/pytestplugin/py/test/testing/test_collect.py
==============================================================================
--- py/branch/pytestplugin/py/test/testing/test_collect.py (original)
+++ py/branch/pytestplugin/py/test/testing/test_collect.py Tue Feb 10 17:07:05 2009
@@ -7,6 +7,7 @@
from test_config import getcolitems
from py.__.test.pycollect import DoctestFileContent
+
class DummyConfig:
def __init__(self):
self._conftest = Conftest()
@@ -18,7 +19,6 @@
return self._conftest.rget(name, fspath)
def setup_module(mod):
- mod.tmpdir = py.test.ensuretemp(mod.__name__)
mod.dummyconfig = DummyConfig()
def test_collect_versus_item():
@@ -26,47 +26,47 @@
assert not issubclass(Collector, Item)
assert not issubclass(Item, Collector)
-def test_ignored_certain_directories():
- tmp = py.test.ensuretemp("ignore_certain_directories")
- tmp.ensure("_darcs", 'test_notfound.py')
- tmp.ensure("CVS", 'test_notfound.py')
- tmp.ensure("{arch}", 'test_notfound.py')
- tmp.ensure(".whatever", 'test_notfound.py')
- tmp.ensure(".bzr", 'test_notfound.py')
- tmp.ensure("normal", 'test_found.py')
- tmp.ensure('test_found.py')
+def test_ignored_certain_directories(tmpdir):
+ tmpdir.ensure("_darcs", 'test_notfound.py')
+ tmpdir.ensure("CVS", 'test_notfound.py')
+ tmpdir.ensure("{arch}", 'test_notfound.py')
+ tmpdir.ensure(".whatever", 'test_notfound.py')
+ tmpdir.ensure(".bzr", 'test_notfound.py')
+ tmpdir.ensure("normal", 'test_found.py')
+ tmpdir.ensure('test_found.py')
- col = py.test.collect.Directory(tmp, config=dummyconfig)
+ col = py.test.collect.Directory(tmpdir, config=dummyconfig)
items = col.collect()
names = [x.name for x in items]
assert len(items) == 2
assert 'normal' in names
assert 'test_found.py' in names
-class TestCollect(suptest.InlineCollection):
- def test_failing_import(self):
- modcol = self.getmodulecol("import alksdjalskdjalkjals")
+class TestCollect:
+ def test_failing_import(self, tsession):
+ modcol = tsession.getmodulecol("import alksdjalskdjalkjals")
py.test.raises(ImportError, modcol.collect)
py.test.raises(ImportError, modcol.collect)
py.test.raises(ImportError, modcol.run)
- def test_syntax_error_in_module(self):
- modcol = self.getmodulecol("this is a syntax error")
+ def test_syntax_error_in_module(self, tsession):
+ modcol = tsession.getmodulecol("this is a syntax error")
py.test.raises(SyntaxError, modcol.collect)
py.test.raises(SyntaxError, modcol.collect)
py.test.raises(SyntaxError, modcol.run)
- def test_listnames_and__getitembynames(self):
- modcol = self.getmodulecol("pass")
+ def test_listnames_and__getitembynames(self, tsession):
+ modcol = tsession.getmodulecol("pass", withinit=True)
names = modcol.listnames()
+ print names
dircol = modcol._config.getfsnode(modcol._config.topdir)
x = dircol._getitembynames(names)
assert modcol.name == x.name
assert modcol.name == x.name
- def test_listnames_getitembynames_custom(self):
- hello = self._makefile(".xxx", hello="world")
- self.makepyfile(conftest="""
+ def test_listnames_getitembynames_custom(self, fstester):
+ hello = fstester._makefile(".xxx", hello="world")
+ fstester.makepyfile(conftest="""
import py
class CustomFile(py.test.collect.File):
pass
@@ -75,7 +75,7 @@
return [CustomFile(self.fspath.join("hello.xxx"), parent=self)]
Directory = MyDirectory
""")
- config = self.parseconfig(hello)
+ config = fstester.parseconfig(hello)
node = config.getfsnode(hello)
assert isinstance(node, py.test.collect.File)
assert node.name == "hello.xxx"
@@ -84,16 +84,16 @@
node = dircol._getitembynames(names)
assert isinstance(node, py.test.collect.File)
- def test_found_certain_testfiles(self):
- p1 = self.makepyfile(test_found = "pass", found_test="pass")
+ def test_found_certain_testfiles(self, fstester):
+ p1 = fstester.makepyfile(test_found = "pass", found_test="pass")
col = py.test.collect.Directory(p1.dirpath(), config=dummyconfig)
items = col.collect() # Directory collect returns files sorted by name
assert len(items) == 2
assert items[1].name == 'test_found.py'
assert items[0].name == 'found_test.py'
- def test_disabled_class(self):
- modcol = self.getmodulecol("""
+ def test_disabled_class(self, tsession):
+ modcol = tsession.getmodulecol("""
class TestClass:
disabled = True
def test_method(self):
@@ -105,8 +105,8 @@
assert isinstance(modcol, py.test.collect.Class)
assert not modcol.collect()
- def test_disabled_module(self):
- modcol = self.getmodulecol("""
+ def test_disabled_module(self, tsession):
+ modcol = tsession.getmodulecol("""
disabled = True
def setup_module(mod):
raise ValueError
@@ -114,8 +114,8 @@
assert not modcol.collect()
assert not modcol.run()
- def test_generative_functions(self):
- modcol = self.getmodulecol("""
+ def test_generative_functions(self, tsession):
+ modcol = tsession.getmodulecol("""
def func1(arg, arg2):
assert arg == arg2
@@ -134,8 +134,8 @@
assert gencolitems[0].name == '[0]'
assert gencolitems[0].obj.func_name == 'func1'
- def test_generative_methods(self):
- modcol = self.getmodulecol("""
+ def test_generative_methods(self, tsession):
+ modcol = tsession.getmodulecol("""
def func1(arg, arg2):
assert arg == arg2
class TestGenMethods:
@@ -152,8 +152,8 @@
assert gencolitems[0].name == '[0]'
assert gencolitems[0].obj.func_name == 'func1'
- def test_generative_functions_with_explicit_names(self):
- modcol = self.getmodulecol("""
+ def test_generative_functions_with_explicit_names(self, tsession):
+ modcol = tsession.getmodulecol("""
def func1(arg, arg2):
assert arg == arg2
@@ -174,8 +174,8 @@
assert gencolitems[1].name == "['fortytwo']"
assert gencolitems[1].obj.func_name == 'func1'
- def test_generative_methods_with_explicit_names(self):
- modcol = self.getmodulecol("""
+ def test_generative_methods_with_explicit_names(self, tsession):
+ modcol = tsession.getmodulecol("""
def func1(arg, arg2):
assert arg == arg2
class TestGenMethods:
@@ -194,8 +194,8 @@
assert gencolitems[1].name == "['m2']"
assert gencolitems[1].obj.func_name == 'func1'
- def test_module_assertion_setup(self):
- modcol = self.getmodulecol("pass")
+ def test_module_assertion_setup(self, tsession):
+ modcol = tsession.getmodulecol("pass")
from py.__.magic import assertion
l = []
py.magic.patch(assertion, "invoke", lambda: l.append(None))
@@ -213,8 +213,8 @@
x = l.pop()
assert x is None
- def test_check_equality_and_cmp_basic(self):
- modcol = self.getmodulecol("""
+ def test_check_equality_and_cmp_basic(self, tsession):
+ modcol = tsession.getmodulecol("""
def test_pass(): pass
def test_fail(): assert 0
""")
@@ -244,39 +244,39 @@
assert [1,2,3] != fn
assert modcol != fn
- def test_directory_file_sorting(self):
- p1 = self.makepyfile(test_one="hello")
+ def test_directory_file_sorting(self, fstester):
+ p1 = fstester.makepyfile(test_one="hello")
p1.dirpath().mkdir("x")
p1.dirpath().mkdir("dir1")
- self.makepyfile(test_two="hello")
+ fstester.makepyfile(test_two="hello")
p1.dirpath().mkdir("dir2")
- config = self.parseconfig()
+ config = fstester.parseconfig()
col = config.getfsnode(p1.dirpath())
names = [x.name for x in col.collect()]
assert names == ["dir1", "dir2", "test_one.py", "test_two.py", "x"]
- def test_collector_deprecated_run_method(self):
- modcol = self.getmodulecol("pass")
+ def test_collector_deprecated_run_method(self, tsession):
+ modcol = tsession.getmodulecol("pass")
res1 = py.test.deprecated_call(modcol.run)
res2 = modcol.collect()
assert res1 == [x.name for x in res2]
- def test_allow_sane_sorting_for_decorators(self):
- modcol = self.getmodulecol("""
- def dec(f):
- g = lambda: f(2)
- g.place_as = f
- return g
+ def test_allow_sane_sorting_for_decorators(self, tsession):
+ modcol = tsession.getmodulecol("""
+ def dec(f):
+ g = lambda: f(2)
+ g.place_as = f
+ return g
- def test_a(y):
- pass
- test_a = dec(test_a)
-
- def test_b(y):
- pass
- test_b = dec(test_b)
- """)
+ def test_a(y):
+ pass
+ test_a = dec(test_a)
+
+ def test_b(y):
+ pass
+ test_b = dec(test_b)
+ """)
colitems = modcol.collect()
assert len(colitems) == 2
f1, f2 = colitems
@@ -358,13 +358,13 @@
assert item.name == "hello.xxx"
assert item.__class__.__name__ == "CustomItem"
-def test_module_file_not_found():
+def test_module_file_not_found(tmpdir):
fn = tmpdir.join('nada','no')
col = py.test.collect.Module(fn, config=dummyconfig)
py.test.raises(py.error.ENOENT, col.collect)
-def test_order_of_execution_generator_same_codeline():
+def test_order_of_execution_generator_same_codeline(tmpdir):
o = tmpdir.ensure('genorder1', dir=1)
o.join("test_order1.py").write(py.code.Source("""
def test_generative_order_of_execution():
@@ -388,7 +388,7 @@
assert passed == 7
assert not skipped and not failed
-def test_order_of_execution_generator_different_codeline():
+def test_order_of_execution_generator_different_codeline(tmpdir):
o = tmpdir.ensure('genorder2', dir=2)
o.join("test_genorder2.py").write(py.code.Source("""
def test_generative_tests_different_codeline():
@@ -419,7 +419,7 @@
assert passed == 4
assert not skipped and not failed
-def test_function_equality():
+def test_function_equality(tmpdir):
config = py.test.config._reparse([tmpdir])
f1 = py.test.collect.Function(name="name", config=config,
args=(1,), callobj=isinstance)
@@ -534,14 +534,10 @@
assert isinstance(items[0], DoctestFileContent)
class TestCollector:
- def setup_method(self, method):
- self.tmpdir = py.test.ensuretemp("%s_%s" %
- (self.__class__.__name__, method.__name__))
-
- def test_totrail_and_back(self):
- a = self.tmpdir.ensure("a", dir=1)
- self.tmpdir.ensure("a", "__init__.py")
- x = self.tmpdir.ensure("a", "trail.py")
+ def test_totrail_and_back(self, tmpdir):
+ a = tmpdir.ensure("a", dir=1)
+ tmpdir.ensure("a", "__init__.py")
+ x = tmpdir.ensure("a", "trail.py")
config = py.test.config._reparse([x])
col = config.getfsnode(x)
trail = col._totrail()
@@ -551,8 +547,8 @@
col2 = py.test.collect.Collector._fromtrail(trail, config)
assert col2.listnames() == col.listnames()
- def test_totrail_topdir_and_beyond(self):
- config = py.test.config._reparse([self.tmpdir])
+ def test_totrail_topdir_and_beyond(self, tmpdir):
+ config = py.test.config._reparse([tmpdir])
col = config.getfsnode(config.topdir)
trail = col._totrail()
assert len(trail) == 2
More information about the pytest-commit
mailing list