def test_example_distribution_minus_x(self): self.source.ensure("sub", "conftest.py").write(py.code.Source(""" dist_hosts = ['localhost:%s'] """ % self.dest)) self.source.ensure("sub", "__init__.py") self.source.ensure("sub", "test_one.py").write(py.code.Source(""" def test_1(): pass def test_x(): import py py.test.skip("aaa") def test_2(): assert 0 def test_3(): raise ValueError(23) def test_4(someargs): pass """)) config = py.test.config._reparse([self.source.join("sub"), '-x']) rsession = RSession(config) allevents = [] rsession.main(reporter=allevents.append) testevents = [x for x in allevents if isinstance(x, repevent.ReceivedItemOutcome)] assert len(testevents) == 3 assert rsession.checkfun()
def test_distribution_rsync_roots_example(self): destdir = py.test.ensuretemp("example_dist_destdir") subdir = "sub_example_dist" tmpdir = self.source tmpdir.ensure(subdir, "conftest.py").write(py.code.Source(""" dist_hosts = ["localhost:%s"] dist_rsync_roots = ["%s", "../py"] """ % (destdir, tmpdir.join(subdir), ))) tmpdir.ensure(subdir, "__init__.py") tmpdir.ensure(subdir, "test_one.py").write(py.code.Source(""" def test_1(): pass def test_2(): assert 0 def test_3(): raise ValueError(23) def test_4(someargs): pass def test_5(): assert __file__ != '%s' #def test_6(): # import py # assert py.__file__ != '%s' """ % (tmpdir.join(subdir), py.__file__))) destdir.join("py").mksymlinkto(py.path.local(py.__file__).dirpath()) config = py.test.config._reparse([tmpdir.join(subdir)]) assert config.topdir == tmpdir assert not tmpdir.join("__init__.py").check() rsession = RSession(config) allevents = [] rsession.main(reporter=allevents.append) testevents = [x for x in allevents if isinstance(x, repevent.ReceivedItemOutcome)] assert len(testevents) print testevents passevents = [i for i in testevents if i.outcome.passed] failevents = [i for i in testevents if i.outcome.excinfo] skippedevents = [i for i in testevents if i.outcome.skipped] assert len(testevents) == 5 assert len(passevents) == 2 assert len(failevents) == 3 tb = failevents[0].outcome.excinfo.traceback assert str(tb[0].path).find("test_one") != -1 assert tb[0].source.find("test_2") != -1 assert failevents[0].outcome.excinfo.typename == 'AssertionError' tb = failevents[1].outcome.excinfo.traceback assert str(tb[0].path).find("test_one") != -1 assert tb[0].source.find("test_3") != -1 assert failevents[1].outcome.excinfo.typename == 'ValueError' assert failevents[1].outcome.excinfo.value == '23' tb = failevents[2].outcome.excinfo.traceback assert failevents[2].outcome.excinfo.typename == 'TypeError' assert str(tb[0].path).find("executor") != -1 assert tb[0].source.find("execute") != -1
def test_nice_level(self): """ Tests if nice level behaviour is ok """ allevents = [] hosts = [HostInfo('localhost:%s' % self.dest)] tmpdir = self.source tmpdir.ensure("__init__.py") tmpdir.ensure("conftest.py").write(py.code.Source(""" dist_hosts = ['localhost:%s'] dist_nicelevel = 10 """ % self.dest)) tmpdir.ensure("test_one.py").write("""def test_nice(): import os assert os.nice(0) == 10 """) config = py.test.config._reparse([tmpdir]) rsession = RSession(config) allevents = [] rsession.main(reporter=allevents.append) testevents = [x for x in allevents if isinstance(x, repevent.ReceivedItemOutcome)] passevents = [x for x in testevents if x.outcome.passed] assert len(passevents) == 1