* rename "rep" to "report" in reporting hooks
* refine docs * bump version data * improve announcement --HG-- branch : 1.0.x
This commit is contained in:
20
py/test/dist/dsession.py
vendored
20
py/test/dist/dsession.py
vendored
@@ -34,16 +34,16 @@ class LoopState(object):
|
||||
return "<LoopState exitstatus=%r shuttingdown=%r len(colitems)=%d>" % (
|
||||
self.exitstatus, self.shuttingdown, len(self.colitems))
|
||||
|
||||
def pytest_runtest_logreport(self, rep):
|
||||
if rep.item in self.dsession.item2nodes:
|
||||
if rep.when != "teardown": # otherwise we have already managed it
|
||||
self.dsession.removeitem(rep.item, rep.node)
|
||||
if rep.failed:
|
||||
def pytest_runtest_logreport(self, report):
|
||||
if report.item in self.dsession.item2nodes:
|
||||
if report.when != "teardown": # otherwise we already managed it
|
||||
self.dsession.removeitem(report.item, report.node)
|
||||
if report.failed:
|
||||
self.testsfailed = True
|
||||
|
||||
def pytest_collectreport(self, rep):
|
||||
if rep.passed:
|
||||
self.colitems.extend(rep.result)
|
||||
def pytest_collectreport(self, report):
|
||||
if report.passed:
|
||||
self.colitems.extend(report.result)
|
||||
|
||||
def pytest_testnodeready(self, node):
|
||||
self.dsession.addnode(node)
|
||||
@@ -199,7 +199,7 @@ class DSession(Session):
|
||||
else:
|
||||
self.config.hook.pytest_collectstart(collector=next)
|
||||
colrep = self.config.hook.pytest_make_collect_report(collector=next)
|
||||
self.queueevent("pytest_collectreport", rep=colrep)
|
||||
self.queueevent("pytest_collectreport", report=colrep)
|
||||
if self.config.option.dist == "each":
|
||||
self.senditems_each(senditems)
|
||||
else:
|
||||
@@ -267,7 +267,7 @@ class DSession(Session):
|
||||
info = "!!! Node %r crashed during running of test %r" %(node, item)
|
||||
rep = runner.ItemTestReport(item=item, excinfo=info, when="???")
|
||||
rep.node = node
|
||||
self.config.hook.pytest_runtest_logreport(rep=rep)
|
||||
self.config.hook.pytest_runtest_logreport(report=rep)
|
||||
|
||||
def setup(self):
|
||||
""" setup any neccessary resources ahead of the test run. """
|
||||
|
||||
274
py/test/dist/testing/acceptance_test.py
vendored
274
py/test/dist/testing/acceptance_test.py
vendored
@@ -1,242 +1,5 @@
|
||||
import py
|
||||
|
||||
EXPECTTIMEOUT=10.0
|
||||
|
||||
class TestGeneralUsage:
|
||||
def test_config_error(self, testdir):
|
||||
testdir.makeconftest("""
|
||||
def pytest_configure(config):
|
||||
raise config.Error("hello")
|
||||
""")
|
||||
result = testdir.runpytest(testdir.tmpdir)
|
||||
assert result.ret != 0
|
||||
assert result.stderr.fnmatch_lines([
|
||||
'*ERROR: hello'
|
||||
])
|
||||
|
||||
def test_config_preparse_plugin_option(self, testdir):
|
||||
testdir.makepyfile(pytest_xyz="""
|
||||
def pytest_addoption(parser):
|
||||
parser.addoption("--xyz", dest="xyz", action="store")
|
||||
""")
|
||||
testdir.makepyfile(test_one="""
|
||||
import py
|
||||
def test_option():
|
||||
assert py.test.config.option.xyz == "123"
|
||||
""")
|
||||
result = testdir.runpytest("-p", "xyz", "--xyz=123")
|
||||
assert result.ret == 0
|
||||
assert result.stdout.fnmatch_lines([
|
||||
'*1 passed*',
|
||||
])
|
||||
|
||||
def test_basetemp(self, testdir):
|
||||
mytemp = testdir.tmpdir.mkdir("mytemp")
|
||||
p = testdir.makepyfile("""
|
||||
import py
|
||||
def test_1():
|
||||
py.test.ensuretemp('xyz')
|
||||
""")
|
||||
result = testdir.runpytest(p, '--basetemp=%s' %mytemp)
|
||||
assert result.ret == 0
|
||||
assert mytemp.join('xyz').check(dir=1)
|
||||
|
||||
def test_assertion_magic(self, testdir):
|
||||
p = testdir.makepyfile("""
|
||||
def test_this():
|
||||
x = 0
|
||||
assert x
|
||||
""")
|
||||
result = testdir.runpytest(p)
|
||||
extra = result.stdout.fnmatch_lines([
|
||||
"> assert x",
|
||||
"E assert 0",
|
||||
])
|
||||
assert result.ret == 1
|
||||
|
||||
def test_nested_import_error(self, testdir):
|
||||
p = testdir.makepyfile("""
|
||||
import import_fails
|
||||
def test_this():
|
||||
assert import_fails.a == 1
|
||||
""")
|
||||
testdir.makepyfile(import_fails="import does_not_work")
|
||||
result = testdir.runpytest(p)
|
||||
extra = result.stdout.fnmatch_lines([
|
||||
"> import import_fails",
|
||||
"E ImportError: No module named does_not_work",
|
||||
])
|
||||
assert result.ret == 1
|
||||
|
||||
def test_skipped_reasons(self, testdir):
|
||||
testdir.makepyfile(
|
||||
test_one="""
|
||||
from conftest import doskip
|
||||
def setup_function(func):
|
||||
doskip()
|
||||
def test_func():
|
||||
pass
|
||||
class TestClass:
|
||||
def test_method(self):
|
||||
doskip()
|
||||
""",
|
||||
test_two = """
|
||||
from conftest import doskip
|
||||
doskip()
|
||||
""",
|
||||
conftest = """
|
||||
import py
|
||||
def doskip():
|
||||
py.test.skip('test')
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
extra = result.stdout.fnmatch_lines([
|
||||
"*test_one.py ss",
|
||||
"*test_two.py S",
|
||||
"___* skipped test summary *_",
|
||||
"*conftest.py:3: *3* Skipped: 'test'",
|
||||
])
|
||||
assert result.ret == 0
|
||||
|
||||
def test_deselected(self, testdir):
|
||||
testpath = testdir.makepyfile("""
|
||||
def test_one():
|
||||
pass
|
||||
def test_two():
|
||||
pass
|
||||
def test_three():
|
||||
pass
|
||||
"""
|
||||
)
|
||||
result = testdir.runpytest("-k", "test_two:", testpath)
|
||||
extra = result.stdout.fnmatch_lines([
|
||||
"*test_deselected.py ..",
|
||||
"=* 1 test*deselected by 'test_two:'*=",
|
||||
])
|
||||
assert result.ret == 0
|
||||
|
||||
def test_no_skip_summary_if_failure(self, testdir):
|
||||
testdir.makepyfile("""
|
||||
import py
|
||||
def test_ok():
|
||||
pass
|
||||
def test_fail():
|
||||
assert 0
|
||||
def test_skip():
|
||||
py.test.skip("dontshow")
|
||||
""")
|
||||
result = testdir.runpytest()
|
||||
assert result.stdout.str().find("skip test summary") == -1
|
||||
assert result.ret == 1
|
||||
|
||||
def test_passes(self, testdir):
|
||||
p1 = testdir.makepyfile("""
|
||||
def test_passes():
|
||||
pass
|
||||
class TestClass:
|
||||
def test_method(self):
|
||||
pass
|
||||
""")
|
||||
old = p1.dirpath().chdir()
|
||||
try:
|
||||
result = testdir.runpytest()
|
||||
finally:
|
||||
old.chdir()
|
||||
extra = result.stdout.fnmatch_lines([
|
||||
"test_passes.py ..",
|
||||
"* 2 pass*",
|
||||
])
|
||||
assert result.ret == 0
|
||||
|
||||
def test_header_trailer_info(self, testdir):
|
||||
p1 = testdir.makepyfile("""
|
||||
def test_passes():
|
||||
pass
|
||||
""")
|
||||
result = testdir.runpytest()
|
||||
verinfo = ".".join(map(str, py.std.sys.version_info[:3]))
|
||||
extra = result.stdout.fnmatch_lines([
|
||||
"*===== test session starts ====*",
|
||||
"python: platform %s -- Python %s*" %(
|
||||
py.std.sys.platform, verinfo), # , py.std.sys.executable),
|
||||
"*test_header_trailer_info.py .",
|
||||
"=* 1 passed in *.[0-9][0-9] seconds *=",
|
||||
])
|
||||
|
||||
def test_traceback_failure(self, testdir):
|
||||
p1 = testdir.makepyfile("""
|
||||
def g():
|
||||
return 2
|
||||
def f(x):
|
||||
assert x == g()
|
||||
def test_onefails():
|
||||
f(3)
|
||||
""")
|
||||
result = testdir.runpytest(p1)
|
||||
result.stdout.fnmatch_lines([
|
||||
"*test_traceback_failure.py F",
|
||||
"====* FAILURES *====",
|
||||
"____*____",
|
||||
"",
|
||||
" def test_onefails():",
|
||||
"> f(3)",
|
||||
"",
|
||||
"*test_*.py:6: ",
|
||||
"_ _ _ *",
|
||||
#"",
|
||||
" def f(x):",
|
||||
"> assert x == g()",
|
||||
"E assert 3 == 2",
|
||||
"E + where 2 = g()",
|
||||
"",
|
||||
"*test_traceback_failure.py:4: AssertionError"
|
||||
])
|
||||
|
||||
|
||||
def test_showlocals(self, testdir):
|
||||
p1 = testdir.makepyfile("""
|
||||
def test_showlocals():
|
||||
x = 3
|
||||
y = "x" * 5000
|
||||
assert 0
|
||||
""")
|
||||
result = testdir.runpytest(p1, '-l')
|
||||
result.stdout.fnmatch_lines([
|
||||
#"_ _ * Locals *",
|
||||
"x* = 3",
|
||||
"y* = 'xxxxxx*"
|
||||
])
|
||||
|
||||
def test_verbose_reporting(self, testdir):
|
||||
p1 = testdir.makepyfile("""
|
||||
import py
|
||||
def test_fail():
|
||||
raise ValueError()
|
||||
def test_pass():
|
||||
pass
|
||||
class TestClass:
|
||||
def test_skip(self):
|
||||
py.test.skip("hello")
|
||||
def test_gen():
|
||||
def check(x):
|
||||
assert x == 1
|
||||
yield check, 0
|
||||
""")
|
||||
result = testdir.runpytest(p1, '-v')
|
||||
result.stdout.fnmatch_lines([
|
||||
"*test_verbose_reporting.py:2: test_fail*FAIL*",
|
||||
"*test_verbose_reporting.py:4: test_pass*PASS*",
|
||||
"*test_verbose_reporting.py:7: TestClass.test_skip*SKIP*",
|
||||
"*test_verbose_reporting.py:10: test_gen*FAIL*",
|
||||
])
|
||||
assert result.ret == 1
|
||||
result = testdir.runpytest(p1, '-v', '-n 1')
|
||||
result.stdout.fnmatch_lines([
|
||||
"*FAIL*test_verbose_reporting.py:2: test_fail*",
|
||||
])
|
||||
assert result.ret == 1
|
||||
|
||||
class TestDistribution:
|
||||
def test_dist_conftest_options(self, testdir):
|
||||
p1 = testdir.tmpdir.ensure("dir", 'p1.py')
|
||||
@@ -383,40 +146,3 @@ class TestDistribution:
|
||||
result.stdout.fnmatch_lines(["2...4"])
|
||||
result.stdout.fnmatch_lines(["2...5"])
|
||||
|
||||
|
||||
class TestInteractive:
|
||||
def test_simple_looponfail_interaction(self, testdir):
|
||||
p1 = testdir.makepyfile("""
|
||||
def test_1():
|
||||
assert 1 == 0
|
||||
""")
|
||||
p1.setmtime(p1.mtime() - 50.0)
|
||||
child = testdir.spawn_pytest("--looponfail %s" % p1)
|
||||
child.expect("assert 1 == 0")
|
||||
child.expect("test_simple_looponfail_interaction.py:")
|
||||
child.expect("1 failed")
|
||||
child.expect("waiting for changes")
|
||||
p1.write(py.code.Source("""
|
||||
def test_1():
|
||||
assert 1 == 1
|
||||
"""))
|
||||
child.expect("MODIFIED.*test_simple_looponfail_interaction.py", timeout=4.0)
|
||||
child.expect("1 passed", timeout=5.0)
|
||||
child.kill(15)
|
||||
|
||||
class TestKeyboardInterrupt:
|
||||
def test_raised_in_testfunction(self, testdir):
|
||||
p1 = testdir.makepyfile("""
|
||||
import py
|
||||
def test_fail():
|
||||
raise ValueError()
|
||||
def test_inter():
|
||||
raise KeyboardInterrupt()
|
||||
""")
|
||||
result = testdir.runpytest(p1)
|
||||
result.stdout.fnmatch_lines([
|
||||
#"*test_inter() INTERRUPTED",
|
||||
"*KEYBOARD INTERRUPT*",
|
||||
"*1 failed*",
|
||||
])
|
||||
|
||||
|
||||
30
py/test/dist/testing/test_dsession.py
vendored
30
py/test/dist/testing/test_dsession.py
vendored
@@ -81,8 +81,8 @@ class TestDSession:
|
||||
session.triggertesting([modcol])
|
||||
name, args, kwargs = session.queue.get(block=False)
|
||||
assert name == 'pytest_collectreport'
|
||||
rep = kwargs['rep']
|
||||
assert len(rep.result) == 1
|
||||
report = kwargs['report']
|
||||
assert len(report.result) == 1
|
||||
|
||||
def test_triggertesting_item(self, testdir):
|
||||
item = testdir.getitem("def test_func(): pass")
|
||||
@@ -134,7 +134,7 @@ class TestDSession:
|
||||
session.queueevent(None)
|
||||
session.loop_once(loopstate)
|
||||
assert node.sent == [[item]]
|
||||
session.queueevent("pytest_runtest_logreport", rep=run(item, node))
|
||||
session.queueevent("pytest_runtest_logreport", report=run(item, node))
|
||||
session.loop_once(loopstate)
|
||||
assert loopstate.shuttingdown
|
||||
assert not loopstate.testsfailed
|
||||
@@ -182,7 +182,7 @@ class TestDSession:
|
||||
item = item1
|
||||
node = nodes[0]
|
||||
when = "call"
|
||||
session.queueevent("pytest_runtest_logreport", rep=rep)
|
||||
session.queueevent("pytest_runtest_logreport", report=rep)
|
||||
reprec = testdir.getreportrecorder(session)
|
||||
print session.item2nodes
|
||||
loopstate = session._initloopstate([])
|
||||
@@ -190,7 +190,7 @@ class TestDSession:
|
||||
session.loop_once(loopstate)
|
||||
assert len(session.item2nodes[item1]) == 1
|
||||
rep.when = "teardown"
|
||||
session.queueevent("pytest_runtest_logreport", rep=rep)
|
||||
session.queueevent("pytest_runtest_logreport", report=rep)
|
||||
session.loop_once(loopstate)
|
||||
assert len(session.item2nodes[item1]) == 1
|
||||
|
||||
@@ -249,7 +249,7 @@ class TestDSession:
|
||||
|
||||
assert node.sent == [[item]]
|
||||
ev = run(item, node, excinfo=excinfo)
|
||||
session.queueevent("pytest_runtest_logreport", rep=ev)
|
||||
session.queueevent("pytest_runtest_logreport", report=ev)
|
||||
session.loop_once(loopstate)
|
||||
assert loopstate.shuttingdown
|
||||
session.queueevent("pytest_testnodedown", node=node, error=None)
|
||||
@@ -286,8 +286,8 @@ class TestDSession:
|
||||
# run tests ourselves and produce reports
|
||||
ev1 = run(items[0], node, "fail")
|
||||
ev2 = run(items[1], node, None)
|
||||
session.queueevent("pytest_runtest_logreport", rep=ev1) # a failing one
|
||||
session.queueevent("pytest_runtest_logreport", rep=ev2)
|
||||
session.queueevent("pytest_runtest_logreport", report=ev1) # a failing one
|
||||
session.queueevent("pytest_runtest_logreport", report=ev2)
|
||||
# now call the loop
|
||||
loopstate = session._initloopstate(items)
|
||||
session.loop_once(loopstate)
|
||||
@@ -302,7 +302,7 @@ class TestDSession:
|
||||
loopstate = session._initloopstate([])
|
||||
loopstate.shuttingdown = True
|
||||
reprec = testdir.getreportrecorder(session)
|
||||
session.queueevent("pytest_runtest_logreport", rep=run(item, node))
|
||||
session.queueevent("pytest_runtest_logreport", report=run(item, node))
|
||||
session.loop_once(loopstate)
|
||||
assert not reprec.getcalls("pytest_testnodedown")
|
||||
session.queueevent("pytest_testnodedown", node=node, error=None)
|
||||
@@ -343,7 +343,7 @@ class TestDSession:
|
||||
node = MockNode()
|
||||
session.addnode(node)
|
||||
session.senditems_load([item])
|
||||
session.queueevent("pytest_runtest_logreport", rep=run(item, node))
|
||||
session.queueevent("pytest_runtest_logreport", report=run(item, node))
|
||||
loopstate = session._initloopstate([])
|
||||
session.loop_once(loopstate)
|
||||
assert node._shutdown is True
|
||||
@@ -369,10 +369,10 @@ class TestDSession:
|
||||
session.senditems_load([item1])
|
||||
# node2pending will become empty when the loop sees the report
|
||||
rep = run(item1, node)
|
||||
session.queueevent("pytest_runtest_logreport", rep=run(item1, node))
|
||||
session.queueevent("pytest_runtest_logreport", report=run(item1, node))
|
||||
|
||||
# but we have a collection pending
|
||||
session.queueevent("pytest_collectreport", rep=colreport)
|
||||
session.queueevent("pytest_collectreport", report=colreport)
|
||||
|
||||
loopstate = session._initloopstate([])
|
||||
session.loop_once(loopstate)
|
||||
@@ -396,11 +396,11 @@ class TestDSession:
|
||||
dsession = DSession(config)
|
||||
hookrecorder = testdir.getreportrecorder(config).hookrecorder
|
||||
dsession.main([config.getfsnode(p1)])
|
||||
rep = hookrecorder.popcall("pytest_runtest_logreport").rep
|
||||
rep = hookrecorder.popcall("pytest_runtest_logreport").report
|
||||
assert rep.passed
|
||||
rep = hookrecorder.popcall("pytest_runtest_logreport").rep
|
||||
rep = hookrecorder.popcall("pytest_runtest_logreport").report
|
||||
assert rep.skipped
|
||||
rep = hookrecorder.popcall("pytest_runtest_logreport").rep
|
||||
rep = hookrecorder.popcall("pytest_runtest_logreport").report
|
||||
assert rep.failed
|
||||
# see that the node is really down
|
||||
node = hookrecorder.popcall("pytest_testnodedown").node
|
||||
|
||||
8
py/test/dist/testing/test_txnode.py
vendored
8
py/test/dist/testing/test_txnode.py
vendored
@@ -115,7 +115,7 @@ class TestMasterSlaveConnection:
|
||||
node = mysetup.makenode(item.config)
|
||||
node.send(item)
|
||||
kwargs = mysetup.geteventargs("pytest_runtest_logreport")
|
||||
rep = kwargs['rep']
|
||||
rep = kwargs['report']
|
||||
assert rep.passed
|
||||
print rep
|
||||
assert rep.item == item
|
||||
@@ -135,10 +135,10 @@ class TestMasterSlaveConnection:
|
||||
node.send(item)
|
||||
for outcome in "passed failed skipped".split():
|
||||
kwargs = mysetup.geteventargs("pytest_runtest_logreport")
|
||||
rep = kwargs['rep']
|
||||
assert getattr(rep, outcome)
|
||||
report = kwargs['report']
|
||||
assert getattr(report, outcome)
|
||||
|
||||
node.sendlist(items)
|
||||
for outcome in "passed failed skipped".split():
|
||||
rep = mysetup.geteventargs("pytest_runtest_logreport")['rep']
|
||||
rep = mysetup.geteventargs("pytest_runtest_logreport")['report']
|
||||
assert getattr(rep, outcome)
|
||||
|
||||
8
py/test/dist/txnode.py
vendored
8
py/test/dist/txnode.py
vendored
@@ -56,9 +56,9 @@ class TXNode(object):
|
||||
self._down = True
|
||||
self.notify("pytest_testnodedown", error=None, node=self)
|
||||
elif eventname == "pytest_runtest_logreport":
|
||||
rep = kwargs['rep']
|
||||
rep = kwargs['report']
|
||||
rep.node = self
|
||||
self.notify("pytest_runtest_logreport", rep=rep)
|
||||
self.notify("pytest_runtest_logreport", report=rep)
|
||||
else:
|
||||
self.notify(eventname, *args, **kwargs)
|
||||
except KeyboardInterrupt:
|
||||
@@ -110,8 +110,8 @@ class SlaveNode(object):
|
||||
def sendevent(self, eventname, *args, **kwargs):
|
||||
self.channel.send((eventname, args, kwargs))
|
||||
|
||||
def pytest_runtest_logreport(self, rep):
|
||||
self.sendevent("pytest_runtest_logreport", rep=rep)
|
||||
def pytest_runtest_logreport(self, report):
|
||||
self.sendevent("pytest_runtest_logreport", report=report)
|
||||
|
||||
def run(self):
|
||||
channel = self.channel
|
||||
|
||||
Reference in New Issue
Block a user