2008-08-16 23:26:59 +08:00
|
|
|
import py
|
|
|
|
from py.__.test.looponfail.remote import LooponfailingSession, LoopState, RemoteControl
|
|
|
|
|
2009-02-27 18:18:27 +08:00
|
|
|
class TestRemoteControl:
|
|
|
|
def test_nofailures(self, testdir):
|
|
|
|
item = testdir.getitem("def test_func(): pass\n")
|
2009-03-18 07:48:07 +08:00
|
|
|
control = RemoteControl(item.config)
|
2008-08-16 23:26:59 +08:00
|
|
|
control.setup()
|
|
|
|
failures = control.runsession()
|
|
|
|
assert not failures
|
|
|
|
|
2009-02-27 18:18:27 +08:00
|
|
|
def test_failures_somewhere(self, testdir):
|
|
|
|
item = testdir.getitem("def test_func(): assert 0\n")
|
2009-03-18 07:48:07 +08:00
|
|
|
control = RemoteControl(item.config)
|
2008-08-16 23:26:59 +08:00
|
|
|
control.setup()
|
|
|
|
failures = control.runsession()
|
|
|
|
assert failures
|
|
|
|
control.setup()
|
|
|
|
item.fspath.write("def test_func(): assert 1\n")
|
|
|
|
(item.fspath + "c").remove()
|
|
|
|
failures = control.runsession(failures)
|
|
|
|
assert not failures
|
|
|
|
|
2009-02-27 18:18:27 +08:00
|
|
|
def test_failure_change(self, testdir):
|
|
|
|
modcol = testdir.getitem("""
|
2008-08-16 23:26:59 +08:00
|
|
|
def test_func():
|
|
|
|
assert 0
|
|
|
|
""")
|
2009-03-18 07:48:07 +08:00
|
|
|
control = RemoteControl(modcol.config)
|
2008-08-16 23:26:59 +08:00
|
|
|
control.setup()
|
|
|
|
failures = control.runsession()
|
|
|
|
assert failures
|
|
|
|
control.setup()
|
|
|
|
modcol.fspath.write(py.code.Source("""
|
|
|
|
def test_func():
|
|
|
|
assert 1
|
|
|
|
def test_new():
|
|
|
|
assert 0
|
|
|
|
"""))
|
|
|
|
(modcol.fspath + "c").remove()
|
|
|
|
failures = control.runsession(failures)
|
|
|
|
assert not failures
|
|
|
|
control.setup()
|
|
|
|
failures = control.runsession()
|
|
|
|
assert failures
|
|
|
|
assert str(failures).find("test_new") != -1
|
|
|
|
|
2009-02-27 18:18:27 +08:00
|
|
|
class TestLooponFailing:
|
2009-03-22 04:07:45 +08:00
|
|
|
def test_looponfail_from_fail_to_ok(self, testdir):
|
2009-02-27 18:18:27 +08:00
|
|
|
modcol = testdir.getmodulecol("""
|
2008-08-16 23:26:59 +08:00
|
|
|
def test_one():
|
|
|
|
x = 0
|
|
|
|
assert x == 1
|
|
|
|
def test_two():
|
|
|
|
assert 1
|
|
|
|
""")
|
2009-03-18 07:48:07 +08:00
|
|
|
session = LooponfailingSession(modcol.config)
|
2008-08-16 23:26:59 +08:00
|
|
|
loopstate = LoopState()
|
|
|
|
session.remotecontrol.setup()
|
|
|
|
session.loop_once(loopstate)
|
|
|
|
assert len(loopstate.colitems) == 1
|
|
|
|
|
|
|
|
modcol.fspath.write(py.code.Source("""
|
|
|
|
def test_one():
|
|
|
|
x = 15
|
|
|
|
assert x == 15
|
|
|
|
def test_two():
|
|
|
|
assert 1
|
|
|
|
"""))
|
|
|
|
assert session.statrecorder.check()
|
|
|
|
session.loop_once(loopstate)
|
|
|
|
assert not loopstate.colitems
|
|
|
|
|
2009-03-22 04:07:45 +08:00
|
|
|
def test_looponfail_from_one_to_two_tests(self, testdir):
|
2009-02-27 18:18:27 +08:00
|
|
|
modcol = testdir.getmodulecol("""
|
2008-08-16 23:26:59 +08:00
|
|
|
def test_one():
|
|
|
|
assert 0
|
|
|
|
""")
|
2009-03-18 07:48:07 +08:00
|
|
|
session = LooponfailingSession(modcol.config)
|
2008-08-16 23:26:59 +08:00
|
|
|
loopstate = LoopState()
|
|
|
|
session.remotecontrol.setup()
|
|
|
|
loopstate.colitems = []
|
|
|
|
session.loop_once(loopstate)
|
|
|
|
assert len(loopstate.colitems) == 1
|
|
|
|
|
|
|
|
modcol.fspath.write(py.code.Source("""
|
|
|
|
def test_one():
|
|
|
|
assert 1 # passes now
|
|
|
|
def test_two():
|
|
|
|
assert 0 # new and fails
|
|
|
|
"""))
|
|
|
|
assert session.statrecorder.check()
|
|
|
|
session.loop_once(loopstate)
|
|
|
|
assert len(loopstate.colitems) == 0
|
|
|
|
|
|
|
|
session.loop_once(loopstate)
|
|
|
|
assert len(loopstate.colitems) == 1
|
2008-09-22 21:15:47 +08:00
|
|
|
|
2009-03-22 04:07:45 +08:00
|
|
|
def test_looponfail_removed_test(self, testdir):
|
2009-02-27 18:18:27 +08:00
|
|
|
modcol = testdir.getmodulecol("""
|
2008-09-22 21:15:47 +08:00
|
|
|
def test_one():
|
|
|
|
assert 0
|
|
|
|
def test_two():
|
|
|
|
assert 0
|
|
|
|
""")
|
2009-03-18 07:48:07 +08:00
|
|
|
session = LooponfailingSession(modcol.config)
|
2008-09-22 21:15:47 +08:00
|
|
|
loopstate = LoopState()
|
|
|
|
session.remotecontrol.setup()
|
|
|
|
loopstate.colitems = []
|
|
|
|
session.loop_once(loopstate)
|
|
|
|
assert len(loopstate.colitems) == 2
|
|
|
|
|
|
|
|
modcol.fspath.write(py.code.Source("""
|
|
|
|
def test_xxx(): # renamed test
|
|
|
|
assert 0
|
|
|
|
def test_two():
|
|
|
|
assert 1 # pass now
|
|
|
|
"""))
|
|
|
|
assert session.statrecorder.check()
|
|
|
|
session.loop_once(loopstate)
|
|
|
|
assert len(loopstate.colitems) == 0
|
|
|
|
|
|
|
|
session.loop_once(loopstate)
|
|
|
|
assert len(loopstate.colitems) == 1
|