[py-svn] r62012 - in py/branch/pytestplugin/py/test: dsession/testing looponfail/testing plugin testing
hpk at codespeak.net
hpk at codespeak.net
Wed Feb 18 17:26:22 CET 2009
Author: hpk
Date: Wed Feb 18 17:26:19 2009
New Revision: 62012
Modified:
py/branch/pytestplugin/py/test/dsession/testing/test_functional_dsession.py
py/branch/pytestplugin/py/test/looponfail/testing/test_remote.py
py/branch/pytestplugin/py/test/plugin/pytest_pytester.py
py/branch/pytestplugin/py/test/testing/test_doctest.py
py/branch/pytestplugin/py/test/testing/test_event.py
py/branch/pytestplugin/py/test/testing/test_recording.py
py/branch/pytestplugin/py/test/testing/test_runner_functional.py
py/branch/pytestplugin/py/test/testing/test_session.py
py/branch/pytestplugin/py/test/testing/test_setup_nested.py
Log:
fixed some more - only two files with old style setup and suptest remain ...
Modified: py/branch/pytestplugin/py/test/dsession/testing/test_functional_dsession.py
==============================================================================
--- py/branch/pytestplugin/py/test/dsession/testing/test_functional_dsession.py (original)
+++ py/branch/pytestplugin/py/test/dsession/testing/test_functional_dsession.py Wed Feb 18 17:26:19 2009
@@ -6,7 +6,6 @@
from py.__.test import event
from py.__.test.dsession.dsession import DSession
from py.__.test.dsession.hostmanage import HostManager, Host
-from py.__.test.testing import suptest
import os
def eventreader(session):
@@ -27,41 +26,41 @@
events.append(ev)
return readevent
-class TestAsyncFunctional(suptest.InlineCollection):
- def test_dist_no_disthost(self):
- config = self.parseconfig(self.tmpdir, '-d')
+class TestAsyncFunctional:
+ def test_dist_no_disthost(self, testdir):
+ config = testdir.parseconfig(testdir.tmpdir, '-d')
py.test.raises(SystemExit, "config.initsession()")
- def test_conftest_options(self):
- self.makepyfile(conftest="""
+ def test_conftest_options(self, testdir):
+ testdir.makepyfile(conftest="""
print "importing conftest"
import py
Option = py.test.config.Option
option = py.test.config.addoptions("someopt",
Option('', '--forcegen', action="store_true", dest="forcegen", default=False))
- """)
- self.makepyfile(__init__="#")
- p1 = self.makepyfile(test_one="""
+ """,
+ )
+ p1 = testdir.makepyfile("""
def test_1():
import py, conftest
print "test_1: py.test.config.option.forcegen", py.test.config.option.forcegen
print "test_1: conftest", conftest
print "test_1: conftest.option.forcegen", conftest.option.forcegen
assert conftest.option.forcegen
- """)
+ """, __init__="#")
print p1
- config = self.parseconfig('-n1', p1, '--forcegen')
+ config = testdir.parseconfig('-n1', p1, '--forcegen')
dsession = DSession(config)
readevent = eventreader(dsession)
dsession.main()
ev = readevent(event.ItemTestReport)
if not ev.passed:
- print ev.outcome.longrepr
+ print ev
assert 0
- def test_dist_some_tests(self):
- self.makepyfile(conftest="dist_hosts=['localhost']\n")
- p1 = self.makepyfile(test_one="""
+ def test_dist_some_tests(self, testdir):
+ testdir.makepyfile(conftest="dist_hosts=['localhost']\n")
+ p1 = testdir.makepyfile(test_one="""
def test_1():
pass
def test_x():
@@ -70,7 +69,7 @@
def test_fail():
assert 0
""")
- config = self.parseconfig('-d', p1)
+ config = testdir.parseconfig('-d', p1)
dsession = DSession(config)
readevent = eventreader(dsession)
dsession.main([config.getfsnode(p1)])
@@ -85,7 +84,7 @@
assert ev.host.hostname == "localhost"
ev = readevent(event.TestrunFinish)
- def test_distribution_rsync_roots_example(self):
+ def test_distribution_rsync_roots_example(self, testdir):
py.test.skip("testing for root rsync needs rework")
destdir = py.test.ensuretemp("example_dist_destdir")
subdir = "sub_example_dist"
@@ -115,28 +114,26 @@
assert config.topdir == tmpdir
assert not tmpdir.join("__init__.py").check()
dist = DSession(config)
- sorter = suptest.events_from_session(dist)
+ sorter = testdir.inline_runsession(dist)
testevents = sorter.get(event.ItemTestReport)
assert len([x for x in testevents if x.passed]) == 2
assert len([x for x in testevents if x.failed]) == 3
assert len([x for x in testevents if x.skipped]) == 0
- def test_nice_level(self):
+ def test_nice_level(self, testdir):
""" Tests if nice level behaviour is ok """
if not hasattr(os, 'nice'):
py.test.skip("no os.nice() available")
- self.makepyfile(conftest="""
+ testdir.makepyfile(conftest="""
dist_hosts=['localhost']
dist_nicelevel = 10
""")
- p1 = self.makepyfile(test_nice="""
+ p1 = testdir.makepyfile("""
def test_nice():
import os
assert os.nice(0) == 10
""")
- config = self.parseconfig('-d', p1)
- session = config.initsession()
- events = suptest.events_from_session(session)
- ev = events.getreport('test_nice')
+ evrec = testdir.inline_run('-d', p1)
+ ev = evrec.getreport('test_nice')
assert ev.passed
Modified: py/branch/pytestplugin/py/test/looponfail/testing/test_remote.py
==============================================================================
--- py/branch/pytestplugin/py/test/looponfail/testing/test_remote.py (original)
+++ py/branch/pytestplugin/py/test/looponfail/testing/test_remote.py Wed Feb 18 17:26:19 2009
@@ -1,17 +1,16 @@
import py
-from py.__.test.testing import suptest
from py.__.test.looponfail.remote import LooponfailingSession, LoopState, RemoteControl
-class TestRemoteControl(suptest.InlineCollection):
- def test_nofailures(self):
- item = self.getitem("def test_func(): pass\n")
+class TestRemoteControl:
+ def test_nofailures(self, testdir):
+ item = testdir.getitem("def test_func(): pass\n")
control = RemoteControl(item._config)
control.setup()
failures = control.runsession()
assert not failures
- def test_failures(self):
- item = self.getitem("def test_func(): assert 0\n")
+ def test_failures(self, testdir):
+ item = testdir.getitem("def test_func(): assert 0\n")
control = RemoteControl(item._config)
control.setup()
failures = control.runsession()
@@ -22,8 +21,8 @@
failures = control.runsession(failures)
assert not failures
- def test_failure_change(self):
- modcol = self.getitem("""
+ def test_failure_change(self, testdir):
+ modcol = testdir.getitem("""
def test_func():
assert 0
""")
@@ -46,9 +45,9 @@
assert failures
assert str(failures).find("test_new") != -1
-class TestLooponFailing(suptest.InlineCollection):
- def test_looponfailing_from_fail_to_ok(self):
- modcol = self.getmodulecol("""
+class TestLooponFailing:
+ def test_looponfailing_from_fail_to_ok(self, testdir):
+ modcol = testdir.getmodulecol("""
def test_one():
x = 0
assert x == 1
@@ -72,8 +71,8 @@
session.loop_once(loopstate)
assert not loopstate.colitems
- def test_looponfailing_from_one_to_two_tests(self):
- modcol = self.getmodulecol("""
+ def test_looponfailing_from_one_to_two_tests(self, testdir):
+ modcol = testdir.getmodulecol("""
def test_one():
assert 0
""")
@@ -97,8 +96,8 @@
session.loop_once(loopstate)
assert len(loopstate.colitems) == 1
- def test_looponfailing_removed_test(self):
- modcol = self.getmodulecol("""
+ def test_looponfailing_removed_test(self, testdir):
+ modcol = testdir.getmodulecol("""
def test_one():
assert 0
def test_two():
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 Wed Feb 18 17:26:19 2009
@@ -16,7 +16,11 @@
class TmpTestdir:
def __init__(self, pyfuncitem):
self.pyfuncitem = pyfuncitem
- self.tmpdir = py.test.ensuretemp("_".join(pyfuncitem.listnames()))
+ name = pyfuncitem.getmodpath(stopatmodule=False)
+ #name = "_".join(pyfuncitem.getmodpath()) # listnames())
+ name = name.replace("()", "_")
+ name = name.replace(".", "_")
+ self.tmpdir = py.test.ensuretemp(name)
self._plugins = []
def _makefile(self, ext, args, kwargs):
@@ -62,6 +66,31 @@
items = list(session.genitems(colitems))
return items, rec
+ def runitem(self, source, **runnerargs):
+ # used from runner functional
+ item = self.getitem(source)
+ # XXX
+ runner = self.pyfuncitem.obj.im_self.getrunner()
+ return runner(item, **runnerargs)
+
+ #evrec = self.inline_runsource(source, *cmdlineargs)
+ #flist = evrec.getnamed("itemtestreport")
+ #assert len(flist) == 1
+ #return flist[0]
+
+ def inline_runsource(self, source, *cmdlineargs):
+ p = self.makepyfile(source)
+ l = list(cmdlineargs) + [p]
+ return self.inline_run(*l)
+
+ def inline_runsession(self, session):
+ config = session.config
+ config.pluginmanager.configure(config)
+ sorter = EventRecorder(config.bus)
+ session.main()
+ config.pluginmanager.unconfigure(config)
+ return sorter
+
def inline_run(self, *args):
config = self.parseconfig(*args)
config.pluginmanager.configure(config)
@@ -80,6 +109,11 @@
assert item is not None, "%r item not found in module:\n%s" %(funcname, source)
return item
+ def getfscol(self, path, configargs=()):
+ self.config = self.parseconfig(path, *configargs)
+ self.session = self.config.initsession()
+ return self.config.getfsnode(path)
+
def getmodulecol(self, source, configargs=(), withinit=False):
kw = {self.pyfuncitem.name: py.code.Source(source).strip()}
path = self.makepyfile(**kw)
Modified: py/branch/pytestplugin/py/test/testing/test_doctest.py
==============================================================================
--- py/branch/pytestplugin/py/test/testing/test_doctest.py (original)
+++ py/branch/pytestplugin/py/test/testing/test_doctest.py Wed Feb 18 17:26:19 2009
@@ -1,34 +1,28 @@
import py
from py.__.test.outcome import Failed
-from py.__.test.testing.suptest import InlineCollection
-def setup_module(mod):
- mod.tmp = py.test.ensuretemp(__name__)
-
-class TestDoctests(InlineCollection):
- def test_simple_docteststring(self):
- txtfile = self.maketxtfile(test_doc="""
+class TestDoctests:
+ def test_simple_docteststring(self, testdir):
+ txtfile = testdir.maketxtfile(test_doc="""
>>> i = 0
>>> i + 1
1
""")
- config = self.parseconfig(txtfile)
- col = config.getfsnode(txtfile)
+ col = testdir.getfscol(path=txtfile)
testitem = col.join(txtfile.basename)
res = testitem.runtest()
assert res is None
-
- def test_doctest_unexpected_exception(self):
- py.test.skip("implement nice doctest repr for unexpected exceptions")
- p = tmp.join("test_doctest_unexpected_exception")
- p.write(py.code.Source("""
+ @py.test.keywords(xfail=True)
+ def test_doctest_unexpected_exception(self, testdir):
+ p = testdir.maketxtfile("""
>>> i = 0
>>> x
2
- """))
- testitem = py.test.collect.DoctestFile(p).join(p.basename)
+ """)
+ col = testdir.getfscol(p)
+ testitem = col.join(p.basename)
excinfo = py.test.raises(Failed, "testitem.runtest()")
repr = testitem.repr_failure(excinfo, ("", ""))
assert repr.reprlocation
Modified: py/branch/pytestplugin/py/test/testing/test_event.py
==============================================================================
--- py/branch/pytestplugin/py/test/testing/test_event.py (original)
+++ py/branch/pytestplugin/py/test/testing/test_event.py Wed Feb 18 17:26:19 2009
@@ -1,7 +1,6 @@
import py
from py.__.test.event import EventBus
from py.__.test import event
-import suptest
from py.__.code.testing.test_excinfo import TWMock
class TestEventBus:
@@ -76,17 +75,17 @@
if py.std.inspect.isclass(value) and issubclass(value, event.BaseEvent):
assert hasattr(event.BaseEvent, value.__name__)
-class TestItemTestReport(suptest.InlineCollection):
- def test_excinfo_is_longrepr(self):
- modcol = self.getmodulecol("def test_ok(): pass")
+class TestItemTestReport:
+ def test_excinfo_is_longrepr(self, testdir):
+ modcol = testdir.getmodulecol("def test_ok(): pass")
ev = event.ItemTestReport(modcol, excinfo="hello")
twmock = TWMock()
ev.toterminal(twmock)
assert twmock.lines
assert twmock.lines[0] == "hello"
- def test_toterminal(self):
- sorter = suptest.events_from_runsource("""
+ def test_toterminal(self, testdir):
+ sorter = testdir.inline_runsource("""
def test_one():
assert 42 == 43
""")
Modified: py/branch/pytestplugin/py/test/testing/test_recording.py
==============================================================================
--- py/branch/pytestplugin/py/test/testing/test_recording.py (original)
+++ py/branch/pytestplugin/py/test/testing/test_recording.py Wed Feb 18 17:26:19 2009
@@ -1,12 +1,9 @@
import py,sys
py.test.skip("implementation missing: recording")
-from py.__.test.testing import suptest
-from py.__.test.acceptance_test import AcceptBase
-
-class TestRecordingAccept(AcceptBase):
- def test_recording_and_back(self):
- p = self.makepyfile(test_one="""
+class TestRecordingAccept:
+ def test_recording_and_back(self, testdir):
+ p = testdir.makepyfile("""
import py
def test_fail():
assert x
Modified: py/branch/pytestplugin/py/test/testing/test_runner_functional.py
==============================================================================
--- py/branch/pytestplugin/py/test/testing/test_runner_functional.py (original)
+++ py/branch/pytestplugin/py/test/testing/test_runner_functional.py Wed Feb 18 17:26:19 2009
@@ -1,12 +1,11 @@
import py
-from py.__.test.testing.suptest import InlineCollection, getItemTestReport
from py.__.test.runner import basic_run_report, forked_run_report, basic_collect_report
from py.__.test.runner import RobustRun
from py.__.code.excinfo import ReprExceptionInfo
-class BaseTests(InlineCollection):
- def test_getwkargs_function(self):
- ev, fn = getItemTestReport("""
+class BaseTests:
+ def test_getwkargs_function(self, testdir):
+ evrec = testdir.inline_runsource("""
import py
provided = []
@@ -26,10 +25,11 @@
assert item._argfinalizers
assert len(provided) == 1
""")
+ ev, = evrec.getnamed("itemtestreport")
assert ev.passed, ev.longrepr
- def test_getwkargs_boundmethod(self):
- ev, fn = getItemTestReport("""
+ def test_getwkargs_boundmethod(self, testdir):
+ evrec = testdir.inline_runsource("""
import py
provided = []
@@ -45,10 +45,11 @@
def test_func(self, hello):
assert hello == "world"
""")
+ ev, = evrec.getnamed("itemtestreport")
assert ev.passed, ev.longrepr
- def test_funcattr(self):
- ev = self.runitem("""
+ def test_funcattr(self, testdir):
+ ev = testdir.runitem("""
import py
@py.test.keywords(xfail="needs refactoring")
def test_func():
@@ -56,8 +57,8 @@
""")
assert ev.keywords['xfail'] == "needs refactoring"
- def test_passfunction(self):
- ev = self.runitem("""
+ def test_passfunction(self, testdir):
+ ev = testdir.runitem("""
def test_func():
pass
""")
@@ -66,8 +67,8 @@
assert ev.shortrepr == "."
assert not hasattr(ev, 'longrepr')
- def test_failfunction(self):
- ev = self.runitem("""
+ def test_failfunction(self, testdir):
+ ev = testdir.runitem("""
def test_func():
assert 0
""")
@@ -78,8 +79,8 @@
assert isinstance(ev.longrepr, ReprExceptionInfo)
assert str(ev.shortrepr) == "F"
- def test_skipfunction(self):
- ev = self.runitem("""
+ def test_skipfunction(self, testdir):
+ ev = testdir.runitem("""
import py
def test_func():
py.test.skip("hello")
@@ -94,8 +95,8 @@
#assert ev.skipped.location.path
#assert not ev.skipped.failurerepr
- def test_skip_in_setup_function(self):
- ev = self.runitem("""
+ def test_skip_in_setup_function(self, testdir):
+ ev = testdir.runitem("""
import py
def setup_function(func):
py.test.skip("hello")
@@ -110,8 +111,8 @@
#assert ev.skipped.location.lineno == 3
#assert ev.skipped.location.lineno == 3
- def test_failure_in_setup_function(self):
- ev = self.runitem("""
+ def test_failure_in_setup_function(self, testdir):
+ ev = testdir.runitem("""
import py
def setup_function(func):
raise ValueError(42)
@@ -124,8 +125,8 @@
assert ev.failed
assert ev.when == "setup"
- def test_failure_in_teardown_function(self):
- ev = self.runitem("""
+ def test_failure_in_teardown_function(self, testdir):
+ ev = testdir.runitem("""
import py
def teardown_function(func):
raise ValueError(42)
@@ -140,14 +141,14 @@
assert ev.longrepr.reprcrash.lineno == 3
assert ev.longrepr.reprtraceback.reprentries
- def test_custom_failure_repr(self):
- self.makepyfile(conftest="""
+ def test_custom_failure_repr(self, testdir):
+ testdir.makepyfile(conftest="""
import py
class Function(py.test.collect.Function):
def repr_failure(self, excinfo, outerr):
return "hello"
""")
- ev = self.runitem("""
+ ev = testdir.runitem("""
import py
def test_func():
assert 0
@@ -160,14 +161,14 @@
#assert ev.failed.where.path.basename == "test_func.py"
#assert ev.failed.failurerepr == "hello"
- def test_failure_in_setup_function_ignores_custom_failure_repr(self):
- self.makepyfile(conftest="""
+ def test_failure_in_setup_function_ignores_custom_failure_repr(self, testdir):
+ testdir.makepyfile(conftest="""
import py
class Function(py.test.collect.Function):
def repr_failure(self, excinfo):
assert 0
""")
- ev = self.runitem("""
+ ev = testdir.runitem("""
import py
def setup_function(func):
raise ValueError(42)
@@ -183,8 +184,8 @@
#assert ev.outcome.where.path.basename == "test_func.py"
#assert instanace(ev.failed.failurerepr, PythonFailureRepr)
- def test_capture_in_func(self):
- ev = self.runitem("""
+ def test_capture_in_func(self, testdir):
+ ev = testdir.runitem("""
import py
def setup_function(func):
print >>py.std.sys.stderr, "in setup"
@@ -199,9 +200,9 @@
# assert out == ['in function\nin teardown\n']
# assert err == ['in setup\n']
- def test_systemexit_does_not_bail_out(self):
+ def test_systemexit_does_not_bail_out(self, testdir):
try:
- ev = self.runitem("""
+ ev = testdir.runitem("""
def test_func():
raise SystemExit(42)
""")
@@ -210,10 +211,10 @@
assert ev.failed
assert ev.when == "execute"
- def test_exit_propagates(self):
+ def test_exit_propagates(self, testdir):
from py.__.test.outcome import Exit
try:
- self.runitem("""
+ testdir.runitem("""
from py.__.test.outcome import Exit
def test_func():
raise Exit()
@@ -228,10 +229,10 @@
def getrunner(self):
return basic_run_report
- def test_keyboardinterrupt_propagates(self):
+ def test_keyboardinterrupt_propagates(self, testdir):
from py.__.test.outcome import Exit
try:
- self.runitem("""
+ testdir.runitem("""
def test_func():
raise KeyboardInterrupt("fake")
""")
@@ -240,9 +241,9 @@
else:
py.test.fail("did not raise")
- def test_pdb_on_fail(self):
+ def test_pdb_on_fail(self, testdir):
l = []
- ev = self.runitem("""
+ ev = testdir.runitem("""
def test_func():
assert 0
""", pdb=l.append)
@@ -250,9 +251,9 @@
assert ev.when == "execute"
assert len(l) == 1
- def test_pdb_on_skip(self):
+ def test_pdb_on_skip(self, testdir):
l = []
- ev = self.runitem("""
+ ev = testdir.runitem("""
import py
def test_func():
py.test.skip("hello")
@@ -266,8 +267,8 @@
py.test.skip("no os.fork available")
return forked_run_report
- def test_suicide(self):
- ev = self.runitem("""
+ def test_suicide(self, testdir):
+ ev = testdir.runitem("""
def test_func():
import os
os.kill(os.getpid(), 15)
@@ -275,9 +276,9 @@
assert ev.failed
assert ev.when == "???"
-class TestCollectionEvent(InlineCollection):
- def test_collect_result(self):
- col = self.getmodulecol("""
+class TestCollectionEvent:
+ def test_collect_result(self, testdir):
+ col = testdir.getmodulecol("""
def test_func1():
pass
class TestClass:
@@ -292,8 +293,8 @@
assert res[0].name == "test_func1"
assert res[1].name == "TestClass"
- def test_skip_at_module_scope(self):
- col = self.getmodulecol("""
+ def test_skip_at_module_scope(self, testdir):
+ col = testdir.getmodulecol("""
import py
py.test.skip("hello")
def test_func():
@@ -305,9 +306,9 @@
assert ev.skipped
-class TestRunnerRepr(InlineCollection):
- def test_runner_repr(self):
- item = self.getitem("def test_func(): pass")
+class TestRunnerRepr:
+ def test_runner_repr(self, testdir):
+ item = testdir.getitem("def test_func(): pass")
robustrun = RobustRun(item)
r = repr(robustrun)
assert r
Modified: py/branch/pytestplugin/py/test/testing/test_session.py
==============================================================================
--- py/branch/pytestplugin/py/test/testing/test_session.py (original)
+++ py/branch/pytestplugin/py/test/testing/test_session.py Wed Feb 18 17:26:19 2009
@@ -1,47 +1,43 @@
import py
from py.__.test import event
-from py.__.test.testing import suptest
-def setup_module(mod):
- mod.tmpdir = py.test.ensuretemp(mod.__name__)
-
-class TestKeywordSelection(suptest.InlineSession):
- def test_select_simple(self):
- file_test = self.makepyfile(file_test="""
+class TestKeywordSelection:
+ def test_select_simple(self, testdir):
+ file_test = testdir.makepyfile("""
def test_one(): assert 0
class TestClass(object):
def test_method_one(self):
assert 42 == 43
""")
def check(keyword, name):
- sorter = self.inline_run("-s", "-k", keyword, file_test)
+ sorter = testdir.inline_run("-s", "-k", keyword, file_test)
passed, skipped, failed = sorter.listoutcomes()
assert len(failed) == 1
assert failed[0].colitem.name == name
assert len(sorter.get(event.Deselected)) == 1
for keyword in ['test_one', 'est_on']:
- yield check, keyword, 'test_one'
- yield check, 'TestClass.test', 'test_method_one'
+ #yield check, keyword, 'test_one'
+ check(keyword, 'test_one')
+ check('TestClass.test', 'test_method_one')
- def test_select_extra_keywords(self):
- o = self.tmpdir
- tfile = o.join('test_select.py').write(py.code.Source("""
+ def test_select_extra_keywords(self, testdir):
+ p = testdir.makepyfile(test_select="""
def test_1():
pass
class TestClass:
def test_2(self):
pass
- """))
- conftest = o.join('conftest.py').write(py.code.Source("""
+ """)
+ testdir.makepyfile(conftest="""
import py
class Class(py.test.collect.Class):
def _keywords(self):
return ['xxx', self.name]
- """))
+ """)
for keyword in ('xxx', 'xxx test_2', 'TestClass', 'xxx -test_1',
'TestClass test_2', 'xxx TestClass test_2',):
- sorter = suptest.events_from_cmdline([o, '-s', '-k', keyword])
+ sorter = testdir.inline_run(p.dirpath(), '-s', '-k', keyword)
print "keyword", repr(keyword)
passed, skipped, failed = sorter.listoutcomes()
assert len(passed) == 1
@@ -50,13 +46,13 @@
assert len(dlist) == 1
assert dlist[0].items[0].name == 'test_1'
- def test_select_starton(self):
- threepass = self.makepyfile(test_threepass="""
+ def test_select_starton(self, testdir):
+ threepass = testdir.makepyfile(test_threepass="""
def test_one(): assert 1
def test_two(): assert 1
def test_three(): assert 1
""")
- sorter = self.inline_run("-k", "test_two:", threepass)
+ sorter = testdir.inline_run("-k", "test_two:", threepass)
passed, skipped, failed = sorter.listoutcomes()
assert len(passed) == 2
assert not failed
@@ -65,27 +61,9 @@
item = dlist[0].items[0]
assert item.name == "test_one"
-class SessionTests(suptest.InlineCollection):
- def events_from_cmdline(self, *args):
- paths = [p for p in args if isinstance(p, py.path.local)]
- if not paths:
- args = (self.tmpdir,) + args
- config = self.parseconfig(*args)
- self.session = config.initsession()
- self.sorter = suptest.EventSorter(config, self.session)
- self.session.main()
- return self.sorter
-
- def events_from_runsource(self, source, *args):
- p = self.makepyfile(test_source=source)
- return self.events_from_cmdline(p, *args)
-
- def makepyfile(self, *args, **kw):
- self.tmpdir.ensure('__init__.py')
- return super(SessionTests, self).makepyfile(*args, **kw)
-
- def test_basic_testitem_events(self):
- tfile = self.makepyfile(test_one="""
+class SessionTests:
+ def test_basic_testitem_events(self, testdir):
+ tfile = testdir.makepyfile("""
def test_one():
pass
def test_one_one():
@@ -95,7 +73,7 @@
def test_two(someargs):
pass
""")
- sorter = self.events_from_cmdline(tfile)
+ sorter = testdir.inline_run(tfile)
passed, skipped, failed = sorter.listoutcomes()
assert len(skipped) == 0
assert len(passed) == 1
@@ -110,8 +88,8 @@
col = colstarted[0].collector
assert isinstance(col, py.test.collect.Module)
- def test_nested_import_error(self):
- tfile = self.makepyfile(test_one="""
+ def test_nested_import_error(self, testdir):
+ tfile = testdir.makepyfile("""
import import_fails
def test_this():
assert import_fails.a == 1
@@ -119,19 +97,18 @@
import does_not_work
a = 1
""")
- sorter = self.events_from_cmdline()
+ sorter = testdir.inline_run(tfile)
l = sorter.getfailedcollections()
assert len(l) == 1
out = l[0].longrepr.reprcrash.message
assert out.find('does_not_work') != -1
- def test_raises_output(self):
- self.makepyfile(test_one="""
+ def test_raises_output(self, testdir):
+ sorter = testdir.inline_runsource("""
import py
def test_raises_doesnt():
py.test.raises(ValueError, int, "3")
""")
- sorter = self.events_from_cmdline()
passed, skipped, failed = sorter.listoutcomes()
assert len(failed) == 1
out = failed[0].longrepr.reprcrash.message
@@ -139,8 +116,8 @@
print out
py.test.fail("incorrect raises() output")
- def test_generator_yields_None(self):
- sorter = self.events_from_runsource("""
+ def test_generator_yields_None(self, testdir):
+ sorter = testdir.inline_runsource("""
def test_1():
yield None
""")
@@ -149,15 +126,15 @@
i = out.find('TypeError')
assert i != -1
- def test_syntax_error_module(self):
- sorter = self.events_from_runsource("this is really not python")
+ def test_syntax_error_module(self, testdir):
+ sorter = testdir.inline_runsource("this is really not python")
l = sorter.getfailedcollections()
assert len(l) == 1
out = l[0].longrepr.reprcrash.message
assert out.find(str('not python')) != -1
- def test_exit_first_problem(self):
- sorter = self.events_from_runsource("""
+ def test_exit_first_problem(self, testdir):
+ sorter = testdir.inline_runsource("""
def test_one(): assert 0
def test_two(): assert 0
""", '--exitfirst')
@@ -165,8 +142,8 @@
assert failed == 1
assert passed == skipped == 0
- def test_broken_repr(self):
- self.makepyfile(test_broken="""
+ def test_broken_repr(self, testdir):
+ p = testdir.makepyfile("""
import py
class BrokenRepr1:
foo=0
@@ -190,7 +167,7 @@
t = BrokenRepr2()
assert t.foo == 1
""")
- sorter = self.events_from_cmdline()
+ sorter = testdir.inline_run(p)
passed, skipped, failed = sorter.listoutcomes()
assert len(failed) == 2
out = failed[0].longrepr.reprcrash.message
@@ -199,9 +176,8 @@
assert (out.find("[unknown exception raised in repr()]") != -1 or
out.find("TypeError") != -1)
- def test_skip_by_conftest_directory(self):
- from py.__.test import outcome
- self.makepyfile(conftest="""
+ def test_skip_by_conftest_directory(self, testdir):
+ testdir.makepyfile(conftest="""
import py
class Directory(py.test.collect.Directory):
def collect(self):
@@ -209,14 +185,14 @@
""", test_file="""
def test_one(): pass
""")
- sorter = self.events_from_cmdline()
+ sorter = testdir.inline_run(testdir.tmpdir)
skips = sorter.get(event.CollectionReport)
assert len(skips) == 1
assert skips[0].skipped
class TestNewSession(SessionTests):
- def test_pdb_run(self):
- tfile = self.makepyfile(test_one="""
+ def test_pdb_run(self, testdir):
+ tfile = testdir.makepyfile("""
def test_usepdb():
assert 0
""")
@@ -225,7 +201,7 @@
l.append(args)
py.magic.patch(py.__.test.custompdb, 'post_mortem', mypdb)
try:
- sorter = self.events_from_cmdline('--pdb')
+ sorter = testdir.inline_run('--pdb', tfile)
finally:
py.magic.revert(py.__.test.custompdb, 'post_mortem')
rep = sorter.getreport("test_usepdb")
@@ -234,8 +210,8 @@
tb = py.code.Traceback(l[0][0])
assert tb[-1].name == "test_usepdb"
- def test_order_of_execution(self):
- sorter = self.events_from_runsource("""
+ def test_order_of_execution(self, testdir):
+ sorter = testdir.inline_runsource("""
l = []
def test_1():
l.append(1)
@@ -259,8 +235,8 @@
assert passed == 7
# also test listnames() here ...
- def test_collect_only_with_various_situations(self):
- p = self.makepyfile(
+ def test_collect_only_with_various_situations(self, testdir):
+ p = testdir.makepyfile(
test_one="""
def test_one():
raise ValueError()
@@ -276,9 +252,10 @@
import py
py.test.skip('xxx')
""",
- test_three="xxxdsadsadsadsa"
+ test_three="xxxdsadsadsadsa",
+ __init__=""
)
- sorter = self.events_from_cmdline('--collectonly')
+ sorter = testdir.inline_run('--collectonly', p.dirpath())
itemstarted = sorter.get(event.ItemStart)
assert len(itemstarted) == 3
Modified: py/branch/pytestplugin/py/test/testing/test_setup_nested.py
==============================================================================
--- py/branch/pytestplugin/py/test/testing/test_setup_nested.py (original)
+++ py/branch/pytestplugin/py/test/testing/test_setup_nested.py Wed Feb 18 17:26:19 2009
@@ -2,11 +2,8 @@
# test correct setup/teardowns at
# module, class, and instance level
-import py
-import suptest
-
-def test_module_and_function_setup():
- sorter = suptest.events_from_runsource("""
+def test_module_and_function_setup(testdir):
+ sorter = testdir.inline_runsource("""
modlevel = []
def setup_module(module):
assert not modlevel
@@ -35,8 +32,8 @@
rep = sorter.getreport("test_module")
assert rep.passed
-def test_class_setup():
- sorter = suptest.events_from_runsource("""
+def test_class_setup(testdir):
+ sorter = testdir.inline_runsource("""
class TestSimpleClassSetup:
clslevel = []
def setup_class(cls):
@@ -58,8 +55,8 @@
""")
sorter.assertoutcome(passed=1+2+1)
-def test_method_setup():
- sorter = suptest.events_from_runsource("""
+def test_method_setup(testdir):
+ sorter = testdir.inline_runsource("""
class TestSetupMethod:
def setup_method(self, meth):
self.methsetup = meth
@@ -74,8 +71,8 @@
""")
sorter.assertoutcome(passed=2)
-def test_method_generator_setup():
- sorter = suptest.events_from_runsource("""
+def test_method_generator_setup(testdir):
+ sorter = testdir.inline_runsource("""
class TestSetupTeardownOnInstance:
def setup_class(cls):
cls.classsetup = True
@@ -96,8 +93,8 @@
""")
sorter.assertoutcome(passed=1, failed=1)
-def test_func_generator_setup():
- sorter = suptest.events_from_runsource("""
+def test_func_generator_setup(testdir):
+ sorter = testdir.inline_runsource("""
import sys
def setup_module(mod):
@@ -124,8 +121,8 @@
rep = sorter.getreport("test_one")
assert rep.passed
-def test_method_setup_uses_fresh_instances():
- sorter = suptest.events_from_runsource("""
+def test_method_setup_uses_fresh_instances(testdir):
+ sorter = testdir.inline_runsource("""
class TestSelfState1:
def __init__(self):
self.hello = 42
More information about the pytest-commit
mailing list