Esempio n. 1
0
def forked_run_report(item):
    # for now, we run setup/teardown in the subprocess
    # XXX optionally allow sharing of setup/teardown
    from _pytest.runner import runtestprotocol
    EXITSTATUS_TESTEXIT = 4
    import marshal
    from xdist.remote import serialize_report
    from xdist.slavemanage import unserialize_report

    def runforked():
        try:
            reports = runtestprotocol(item, log=False)
        except KeyboardInterrupt:
            py.std.os._exit(EXITSTATUS_TESTEXIT)
        return marshal.dumps([serialize_report(x) for x in reports])

    ff = py.process.ForkedFunc(runforked)
    result = ff.waitfinish()
    if result.retval is not None:
        report_dumps = marshal.loads(result.retval)
        return [unserialize_report("testreport", x) for x in report_dumps]
    else:
        if result.exitstatus == EXITSTATUS_TESTEXIT:
            py.test.exit("forked test item %s raised Exit" % (item,))
        return [report_process_crash(item, result)]
Esempio n. 2
0
def forked_run_report(item):
    # for now, we run setup/teardown in the subprocess
    # XXX optionally allow sharing of setup/teardown
    from _pytest.runner import runtestprotocol
    EXITSTATUS_TESTEXIT = 4
    import marshal
    from xdist.remote import serialize_report
    from xdist.slavemanage import unserialize_report

    def runforked():
        try:
            reports = runtestprotocol(item, log=False)
        except KeyboardInterrupt:
            py.std.os._exit(EXITSTATUS_TESTEXIT)
        return marshal.dumps([serialize_report(x) for x in reports])

    ff = py.process.ForkedFunc(runforked)
    result = ff.waitfinish()
    if result.retval is not None:
        report_dumps = marshal.loads(result.retval)
        return [unserialize_report("testreport", x) for x in report_dumps]
    else:
        if result.exitstatus == EXITSTATUS_TESTEXIT:
            py.test.exit("forked test item %s raised Exit" % (item, ))
        return [report_process_crash(item, result)]
Esempio n. 3
0
 def test_basic_collect_and_runtests(self, slave):
     slave.testdir.makepyfile(
         """
         def test_func():
             pass
     """
     )
     slave.setup()
     ev = slave.popevent()
     assert ev.name == "slaveready"
     ev = slave.popevent()
     assert ev.name == "collectionstart"
     assert not ev.kwargs
     ev = slave.popevent("collectionfinish")
     assert ev.kwargs["topdir"] == slave.testdir.tmpdir
     ids = ev.kwargs["ids"]
     assert len(ids) == 1
     slave.sendcommand("runtests", indices=list(range(len(ids))))
     slave.sendcommand("shutdown")
     ev = slave.popevent("logstart")
     assert ev.kwargs["nodeid"].endswith("test_func")
     assert len(ev.kwargs["location"]) == 3
     ev = slave.popevent("testreport")  # setup
     ev = slave.popevent("testreport")
     assert ev.name == "testreport"
     rep = unserialize_report(ev.name, ev.kwargs["data"])
     assert rep.nodeid.endswith("::test_func")
     assert rep.passed
     assert rep.when == "call"
     ev = slave.popevent("slavefinished")
     assert "slaveoutput" in ev.kwargs
Esempio n. 4
0
 def test_itemreport_outcomes(self, testdir):
     reprec = testdir.inline_runsource("""
         import py
         def test_pass(): pass
         def test_fail(): 0/0
         @py.test.mark.skipif("True")
         def test_skip(): pass
         def test_skip_imperative():
             py.test.skip("hello")
         @py.test.mark.xfail("True")
         def test_xfail(): 0/0
         def test_xfail_imperative():
             py.test.xfail("hello")
     """)
     reports = reprec.getreports("pytest_runtest_logreport")
     assert len(reports) == 17 # with setup/teardown "passed" reports
     for rep in reports:
         d = serialize_report(rep)
         check_marshallable(d)
         newrep = unserialize_report("testreport", d)
         assert newrep.passed == rep.passed
         assert newrep.failed == rep.failed
         assert newrep.skipped == rep.skipped
         if newrep.skipped and not hasattr(newrep, "wasxfail"):
             assert len(newrep.longrepr) == 3
         assert newrep.outcome == rep.outcome
         assert newrep.when == rep.when
         assert newrep.keywords == rep.keywords
         if rep.failed:
             assert newrep.longrepr == str(rep.longrepr)
Esempio n. 5
0
    def test_reprentries_serialization_170(self, testdir):
        from _pytest._code.code import ReprEntry
        reprec = testdir.inline_runsource(
            """
                            def test_repr_entry():
                                x = 0
                                assert x
                        """, '--showlocals')
        reports = reprec.getreports("pytest_runtest_logreport")
        assert len(reports) == 3
        rep = reports[1]
        d = serialize_report(rep)
        a = unserialize_report("testreport", d)

        rep_entries = rep.longrepr.reprtraceback.reprentries
        a_entries = a.longrepr.reprtraceback.reprentries
        for i in range(len(a_entries)):
            assert isinstance(rep_entries[i], ReprEntry)
            assert rep_entries[i].lines == a_entries[i].lines
            assert rep_entries[i].localssep == a_entries[i].localssep
            assert rep_entries[i].reprfileloc.lineno == a_entries[
                i].reprfileloc.lineno
            assert rep_entries[i].reprfileloc.message == a_entries[
                i].reprfileloc.message
            assert rep_entries[i].reprfileloc.path == a_entries[
                i].reprfileloc.path
            assert rep_entries[i].reprfuncargs.args == a_entries[
                i].reprfuncargs.args
            assert rep_entries[i].reprlocals.lines == a_entries[
                i].reprlocals.lines
            assert rep_entries[i].style == a_entries[i].style
Esempio n. 6
0
 def test_basic_collect_and_runtests(self, slave):
     p = slave.testdir.makepyfile("""
         def test_func():
             pass
     """)
     slave.setup()
     ev = slave.popevent()
     assert ev.name == "slaveready"
     ev = slave.popevent()
     assert ev.name == "collectionstart"
     assert not ev.kwargs
     ev = slave.popevent("collectionfinish")
     assert ev.kwargs['topdir'] == slave.testdir.tmpdir
     ids = ev.kwargs['ids']
     assert len(ids) == 1
     slave.sendcommand("runtests", ids=ids)
     slave.sendcommand("shutdown")
     ev = slave.popevent("testreport") # setup
     ev = slave.popevent("testreport")
     assert ev.name == "testreport"
     rep = unserialize_report(ev.name, ev.kwargs['data'])
     assert rep.nodeid.endswith("::test_func")
     assert rep.passed
     assert rep.when == "call"
     ev = slave.popevent("slavefinished")
     assert 'slaveoutput' in ev.kwargs
Esempio n. 7
0
 def test_itemreport_outcomes(self, testdir):
     reprec = testdir.inline_runsource("""
         import py
         def test_pass(): pass
         def test_fail(): 0/0
         @py.test.mark.skipif("True")
         def test_skip(): pass
         def test_skip_imperative():
             py.test.skip("hello")
         @py.test.mark.xfail("True")
         def test_xfail(): 0/0
         def test_xfail_imperative():
             py.test.xfail("hello")
     """)
     reports = reprec.getreports("pytest_runtest_logreport")
     assert len(reports) == 17  # with setup/teardown "passed" reports
     for rep in reports:
         d = serialize_report(rep)
         check_marshallable(d)
         newrep = unserialize_report("testreport", d)
         assert newrep.passed == rep.passed
         assert newrep.failed == rep.failed
         assert newrep.skipped == rep.skipped
         if newrep.skipped and not hasattr(newrep, "wasxfail"):
             assert len(newrep.longrepr) == 3
         assert newrep.outcome == rep.outcome
         assert newrep.when == rep.when
         assert newrep.keywords == rep.keywords
         if rep.failed:
             assert newrep.longrepr == str(rep.longrepr)
Esempio n. 8
0
 def test_runtests_all(self, slave):
     slave.testdir.makepyfile(
         """
         def test_func(): pass
         def test_func2(): pass
     """
     )
     slave.setup()
     ev = slave.popevent()
     assert ev.name == "slaveready"
     ev = slave.popevent()
     assert ev.name == "collectionstart"
     assert not ev.kwargs
     ev = slave.popevent("collectionfinish")
     ids = ev.kwargs["ids"]
     assert len(ids) == 2
     slave.sendcommand("runtests_all")
     slave.sendcommand("shutdown")
     for func in "::test_func", "::test_func2":
         for i in range(3):  # setup/call/teardown
             ev = slave.popevent("testreport")
             assert ev.name == "testreport"
             rep = unserialize_report(ev.name, ev.kwargs["data"])
             assert rep.nodeid.endswith(func)
     ev = slave.popevent("slavefinished")
     assert "slaveoutput" in ev.kwargs
Esempio n. 9
0
 def test_xdist_report_longrepr_reprcrash_130(self, testdir):
     reprec = testdir.inline_runsource("""
                 import py
                 def test_fail(): assert False, 'Expected Message'
             """)
     reports = reprec.getreports("pytest_runtest_logreport")
     assert len(reports) == 3
     rep = reports[1]
     added_section = ('Failure Metadata', str("metadata metadata"), "*")
     rep.longrepr.sections.append(added_section)
     d = serialize_report(rep)
     check_marshallable(d)
     a = unserialize_report("testreport", d)
     # Check assembled == rep
     assert a.__dict__.keys() == rep.__dict__.keys()
     for key in rep.__dict__.keys():
         if key != 'longrepr':
             assert getattr(a, key) == getattr(rep, key)
     assert rep.longrepr.reprcrash.lineno == a.longrepr.reprcrash.lineno
     assert rep.longrepr.reprcrash.message == a.longrepr.reprcrash.message
     assert rep.longrepr.reprcrash.path == a.longrepr.reprcrash.path
     assert rep.longrepr.reprtraceback.entrysep \
         == a.longrepr.reprtraceback.entrysep
     assert rep.longrepr.reprtraceback.extraline \
         == a.longrepr.reprtraceback.extraline
     assert rep.longrepr.reprtraceback.style \
         == a.longrepr.reprtraceback.style
     assert rep.longrepr.sections == a.longrepr.sections
     # Missing section attribute PR171
     assert added_section in a.longrepr.sections
Esempio n. 10
0
 def test_basic_collect_and_runtests(self, slave):
     slave.testdir.makepyfile("""
         def test_func():
             pass
     """)
     slave.setup()
     ev = slave.popevent()
     assert ev.name == "slaveready"
     ev = slave.popevent()
     assert ev.name == "collectionstart"
     assert not ev.kwargs
     ev = slave.popevent("collectionfinish")
     assert ev.kwargs['topdir'] == slave.testdir.tmpdir
     ids = ev.kwargs['ids']
     assert len(ids) == 1
     slave.sendcommand("runtests", indices=list(range(len(ids))))
     slave.sendcommand("shutdown")
     ev = slave.popevent("logstart")
     assert ev.kwargs["nodeid"].endswith("test_func")
     assert len(ev.kwargs["location"]) == 3
     ev = slave.popevent("testreport")  # setup
     ev = slave.popevent("testreport")
     assert ev.name == "testreport"
     rep = unserialize_report(ev.name, ev.kwargs['data'])
     assert rep.nodeid.endswith("::test_func")
     assert rep.passed
     assert rep.when == "call"
     ev = slave.popevent("slavefinished")
     assert 'slaveoutput' in ev.kwargs
Esempio n. 11
0
 def test_collectreport_passed(self, testdir):
     reprec = testdir.inline_runsource("def test_func(): pass")
     reports = reprec.getreports("pytest_collectreport")
     for rep in reports:
         d = serialize_report(rep)
         check_marshallable(d)
         newrep = unserialize_report("collectreport", d)
         assert newrep.passed == rep.passed
         assert newrep.failed == rep.failed
         assert newrep.skipped == rep.skipped
Esempio n. 12
0
 def test_collectreport_passed(self, testdir):
     reprec = testdir.inline_runsource("def test_func(): pass")
     reports = reprec.getreports("pytest_collectreport")
     for rep in reports:
         d = serialize_report(rep)
         check_marshallable(d)
         newrep = unserialize_report("collectreport", d)
         assert newrep.passed == rep.passed
         assert newrep.failed == rep.failed
         assert newrep.skipped == rep.skipped
Esempio n. 13
0
 def test_remote_collect_fail(self, slave):
     p = slave.testdir.makepyfile("""aasd qwe""")
     slave.setup()
     ev = slave.popevent("collectionstart")
     assert not ev.kwargs
     ev = slave.popevent()
     assert ev.name == "collectreport"
     ev = slave.popevent()
     assert ev.name == "collectreport"
     rep = unserialize_report(ev.name, ev.kwargs['data'])
     assert rep.failed
     ev = slave.popevent("collectionfinish")
     assert not ev.kwargs['ids']
Esempio n. 14
0
 def test_collectreport_fail(self, testdir):
     reprec = testdir.inline_runsource("qwe abc")
     reports = reprec.getreports("pytest_collectreport")
     assert reports
     for rep in reports:
         d = serialize_report(rep)
         check_marshallable(d)
         newrep = unserialize_report("collectreport", d)
         assert newrep.passed == rep.passed
         assert newrep.failed == rep.failed
         assert newrep.skipped == rep.skipped
         if rep.failed:
             assert newrep.longrepr == str(rep.longrepr)
Esempio n. 15
0
 def test_remote_collect_fail(self, slave):
     slave.testdir.makepyfile("""aasd qwe""")
     slave.setup()
     ev = slave.popevent("collectionstart")
     assert not ev.kwargs
     ev = slave.popevent()
     assert ev.name == "collectreport"
     ev = slave.popevent()
     assert ev.name == "collectreport"
     rep = unserialize_report(ev.name, ev.kwargs['data'])
     assert rep.failed
     ev = slave.popevent("collectionfinish")
     assert not ev.kwargs['ids']
Esempio n. 16
0
 def test_collectreport_fail(self, testdir):
     reprec = testdir.inline_runsource("qwe abc")
     reports = reprec.getreports("pytest_collectreport")
     assert reports
     for rep in reports:
         d = serialize_report(rep)
         check_marshallable(d)
         newrep = unserialize_report("collectreport", d)
         assert newrep.passed == rep.passed
         assert newrep.failed == rep.failed
         assert newrep.skipped == rep.skipped
         if rep.failed:
             assert newrep.longrepr == str(rep.longrepr)
Esempio n. 17
0
 def test_remote_collect_skip(self, slave):
     p = slave.testdir.makepyfile("""
         import py
         py.test.skip("hello")
     """)
     slave.setup()
     ev = slave.popevent("collectionstart")
     assert not ev.kwargs
     ev = slave.popevent()
     assert ev.name == "collectreport"
     ev = slave.popevent()
     assert ev.name == "collectreport"
     rep = unserialize_report(ev.name, ev.kwargs['data'])
     assert rep.skipped
     ev = slave.popevent("collectionfinish")
     assert not ev.kwargs['ids']
Esempio n. 18
0
 def test_remote_collect_skip(self, slave):
     slave.testdir.makepyfile("""
         import py
         py.test.skip("hello")
     """)
     slave.setup()
     ev = slave.popevent("collectionstart")
     assert not ev.kwargs
     ev = slave.popevent()
     assert ev.name == "collectreport"
     ev = slave.popevent()
     assert ev.name == "collectreport"
     rep = unserialize_report(ev.name, ev.kwargs['data'])
     assert rep.skipped
     ev = slave.popevent("collectionfinish")
     assert not ev.kwargs['ids']
Esempio n. 19
0
    def test_reprentries_serialization_196(self, testdir):
        from _pytest._code.code import ReprEntryNative
        reprec = testdir.inline_runsource(
            """
                            def test_repr_entry_native():
                                x = 0
                                assert x
                        """, '--tb=native')
        reports = reprec.getreports("pytest_runtest_logreport")
        assert len(reports) == 3
        rep = reports[1]
        d = serialize_report(rep)
        a = unserialize_report("testreport", d)

        rep_entries = rep.longrepr.reprtraceback.reprentries
        a_entries = a.longrepr.reprtraceback.reprentries
        for i in range(len(a_entries)):
            assert isinstance(rep_entries[i], ReprEntryNative)
            assert rep_entries[i].lines == a_entries[i].lines
Esempio n. 20
0
    def test_reprentries_serialization_170(self, testdir):
        reprec = testdir.inline_runsource(
            """
                            def test_fail():
                                x = 0
                                assert x
                        """, '--showlocals', '-n1')
        reports = reprec.getreports("pytest_runtest_logreport")
        assert len(reports) == 3
        rep = reports[1]
        d = serialize_report(rep)
        a = unserialize_report("testreport", d)

        rep_entries = rep.longrepr.reprtraceback.reprentries
        a_entries = a.longrepr.reprtraceback.reprentries
        assert rep_entries == a_entries
        for i in range(len(a_entries)):
            assert rep_entries[i].lines == a_entries[i].lines
            assert rep_entries[i].localssep == a_entries[i].localssep
            assert rep_entries[i].reprfileloc == a_entries[i].reprfileloc
            assert rep_entries[i].reprfuncargs == a_entries[i].reprfuncargs
            assert rep_entries[i].reprlocals == a_entries[i].reprlocals
            assert rep_entries[i].style == a_entries[i].style
Esempio n. 21
0
 def test_runtests_all(self, slave):
     slave.testdir.makepyfile("""
         def test_func(): pass
         def test_func2(): pass
     """)
     slave.setup()
     ev = slave.popevent()
     assert ev.name == "slaveready"
     ev = slave.popevent()
     assert ev.name == "collectionstart"
     assert not ev.kwargs
     ev = slave.popevent("collectionfinish")
     ids = ev.kwargs['ids']
     assert len(ids) == 2
     slave.sendcommand("runtests_all", )
     slave.sendcommand("shutdown", )
     for func in "::test_func", "::test_func2":
         for i in range(3):  # setup/call/teardown
             ev = slave.popevent("testreport")
             assert ev.name == "testreport"
             rep = unserialize_report(ev.name, ev.kwargs['data'])
             assert rep.nodeid.endswith(func)
     ev = slave.popevent("slavefinished")
     assert 'slaveoutput' in ev.kwargs