* refix handling of partial setup failures
* shuffle / consolidate related tests * re-gen setup.py --HG-- branch : 1.0.x
This commit is contained in:
@@ -19,7 +19,7 @@ For questions please check out http://pylib.org/contact.html
|
||||
"""
|
||||
from initpkg import initpkg
|
||||
|
||||
version = "1.0.0b7"
|
||||
version = "1.0.0b8"
|
||||
|
||||
initpkg(__name__,
|
||||
description = "py.test and pylib: advanced testing tool and networking lib",
|
||||
|
||||
@@ -362,6 +362,7 @@ def test_deindent():
|
||||
|
||||
class TestApigenLinkRole:
|
||||
disabled = True
|
||||
|
||||
# these tests are moved here from the former py/doc/conftest.py
|
||||
def test_resolve_linkrole(self):
|
||||
from py.__.doc.conftest import get_apigen_relpath
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
"""
|
||||
collect and run test items.
|
||||
|
||||
* executing test items
|
||||
* running collectors
|
||||
* and generating report events about it
|
||||
collect and run test items and creating reports.
|
||||
"""
|
||||
|
||||
import py
|
||||
@@ -53,7 +49,7 @@ def runtestprotocol(item, log=True):
|
||||
reports = [rep]
|
||||
if rep.passed:
|
||||
reports.append(call_and_report(item, "call", log))
|
||||
reports.append(call_and_report(item, "teardown", log))
|
||||
reports.append(call_and_report(item, "teardown", log))
|
||||
return reports
|
||||
|
||||
def pytest_runtest_setup(item):
|
||||
@@ -225,11 +221,14 @@ class SetupState(object):
|
||||
colitem = self.stack.pop()
|
||||
self._teardown_with_finalization(colitem)
|
||||
|
||||
def _teardown_with_finalization(self, colitem):
|
||||
def _callfinalizers(self, colitem):
|
||||
finalizers = self._finalizers.pop(colitem, None)
|
||||
while finalizers:
|
||||
fin = finalizers.pop()
|
||||
fin()
|
||||
|
||||
def _teardown_with_finalization(self, colitem):
|
||||
self._callfinalizers(colitem)
|
||||
if colitem:
|
||||
colitem.teardown()
|
||||
for colitem in self._finalizers:
|
||||
@@ -242,17 +241,19 @@ class SetupState(object):
|
||||
assert not self._finalizers
|
||||
|
||||
def teardown_exact(self, item):
|
||||
assert self.stack and self.stack[-1] == item
|
||||
self._pop_and_teardown()
|
||||
if item == self.stack[-1]:
|
||||
self._pop_and_teardown()
|
||||
else:
|
||||
self._callfinalizers(item)
|
||||
|
||||
def prepare(self, colitem):
|
||||
""" setup objects along the collector chain to the test-method
|
||||
Teardown any unneccessary previously setup objects."""
|
||||
and teardown previously setup objects."""
|
||||
needed_collectors = colitem.listchain()
|
||||
while self.stack:
|
||||
if self.stack == needed_collectors[:len(self.stack)]:
|
||||
break
|
||||
self._pop_and_teardown()
|
||||
for col in needed_collectors[len(self.stack):]:
|
||||
self.stack.append(col)
|
||||
col.setup()
|
||||
self.stack.append(col)
|
||||
|
||||
@@ -86,7 +86,8 @@ class BaseFunctionalTests:
|
||||
#assert rep.skipped.reason == "hello"
|
||||
#assert rep.skipped.location.lineno == 3
|
||||
#assert rep.skipped.location.lineno == 3
|
||||
assert len(reports) == 1
|
||||
assert len(reports) == 2
|
||||
assert reports[1].passed # teardown
|
||||
|
||||
def test_failure_in_setup_function(self, testdir):
|
||||
reports = testdir.runitem("""
|
||||
@@ -101,7 +102,7 @@ class BaseFunctionalTests:
|
||||
assert not rep.passed
|
||||
assert rep.failed
|
||||
assert rep.when == "setup"
|
||||
assert len(reports) == 1
|
||||
assert len(reports) == 2
|
||||
|
||||
def test_failure_in_teardown_function(self, testdir):
|
||||
reports = testdir.runitem("""
|
||||
@@ -156,7 +157,7 @@ class BaseFunctionalTests:
|
||||
def test_func():
|
||||
pass
|
||||
""")
|
||||
assert len(reports) == 1
|
||||
assert len(reports) == 2
|
||||
rep = reports[0]
|
||||
print rep
|
||||
assert not rep.skipped
|
||||
|
||||
@@ -55,6 +55,7 @@ def test_class_setup(testdir):
|
||||
""")
|
||||
reprec.assertoutcome(passed=1+2+1)
|
||||
|
||||
|
||||
def test_method_setup(testdir):
|
||||
reprec = testdir.inline_runsource("""
|
||||
class TestSetupMethod:
|
||||
@@ -221,30 +221,6 @@ class TestPytestPluginInteractions:
|
||||
assert not pluginmanager.listattr("hello")
|
||||
assert pluginmanager.listattr("x") == [42]
|
||||
|
||||
@py.test.mark.xfail # setup call methods
|
||||
def test_call_setup_participants(self, testdir):
|
||||
testdir.makepyfile(
|
||||
conftest="""
|
||||
import py
|
||||
def pytest_method(self, x):
|
||||
return x+1
|
||||
pytest_plugin = "pytest_someplugin",
|
||||
"""
|
||||
)
|
||||
testdir.makepyfile(pytest_someplugin="""
|
||||
def pytest_method(self, x):
|
||||
return x+1
|
||||
""")
|
||||
modcol = testdir.getmodulecol("""
|
||||
def pytest_method(x):
|
||||
return x+0
|
||||
""")
|
||||
l = []
|
||||
call = modcol.config.pluginmanager.setupcall(modcol, "pytest_method", 1)
|
||||
assert len(call.methods) == 3
|
||||
results = call.execute()
|
||||
assert results == [1,2,2]
|
||||
|
||||
def test_collectattr():
|
||||
class A:
|
||||
def pytest_hello(self):
|
||||
|
||||
@@ -39,6 +39,7 @@ class TestModule:
|
||||
modcol = testdir.getmodulecol("pytest_plugins='xasdlkj',")
|
||||
py.test.raises(ImportError, "modcol.obj")
|
||||
|
||||
class TestDisabled:
|
||||
def test_disabled_module(self, testdir):
|
||||
modcol = testdir.getmodulecol("""
|
||||
disabled = True
|
||||
@@ -51,7 +52,6 @@ class TestModule:
|
||||
assert len(l) == 1
|
||||
py.test.raises(Skipped, "modcol.setup()")
|
||||
|
||||
class TestClass:
|
||||
def test_disabled_class(self, testdir):
|
||||
modcol = testdir.getmodulecol("""
|
||||
class TestClass:
|
||||
@@ -67,6 +67,15 @@ class TestClass:
|
||||
assert len(l) == 1
|
||||
py.test.raises(Skipped, "modcol.setup()")
|
||||
|
||||
def test_disabled_class_functional(self, testdir):
|
||||
reprec = testdir.inline_runsource("""
|
||||
class TestSimpleClassSetup:
|
||||
disabled = True
|
||||
def test_classlevel(self): pass
|
||||
def test_classlevel2(self): pass
|
||||
""")
|
||||
reprec.assertoutcome(skipped=2)
|
||||
|
||||
class TestGenerator:
|
||||
def test_generative_functions(self, testdir):
|
||||
modcol = testdir.getmodulecol("""
|
||||
|
||||
Reference in New Issue
Block a user