Beispiel #1
0
 def test_rewrite(self, testdir, monkeypatch):
     config = testdir.parseconfig()
     f = py.io.TextIO()
     monkeypatch.setattr(f, "isatty", lambda *args: True)
     tr = TerminalReporter(config, f)
     tr._tw.fullwidth = 10
     tr.write("hello")
     tr.rewrite("hey", erase=True)
     assert f.getvalue() == "hello" + "\r" + "hey" + (6 * " ")
Beispiel #2
0
 def test_rewrite(self, testdir, monkeypatch):
     config = testdir.parseconfig()
     f = py.io.TextIO()
     monkeypatch.setattr(f, 'isatty', lambda *args: True)
     tr = TerminalReporter(config, f)
     tr._tw.fullwidth = 10
     tr.write('hello')
     tr.rewrite('hey', erase=True)
     assert f.getvalue() == 'hello' + '\r' + 'hey' + (6 * ' ')
Beispiel #3
0
 def test_rewrite(self, testdir, monkeypatch):
     config = testdir.parseconfig()
     f = py.io.TextIO()
     monkeypatch.setattr(f, 'isatty', lambda *args: True)
     tr = TerminalReporter(config, f)
     tr.writer.fullwidth = 10
     tr.write('hello')
     tr.rewrite('hey', erase=True)
     assert f.getvalue() == 'hello' + '\r' + 'hey' + (7 * ' ')
Beispiel #4
0
def perform_collect_and_run(session):
    """Collect and run tests streaming from the redis queue."""
    # This mimics the internal pytest collect loop, but shortened
    # while running tests as soon as they are found.
    term = TerminalReporter(session.config)

    redis_connection = get_redis_connection(session.config)

    redis_list = populate_test_generator(session,
                                         redis_connection)


    default_verbosity = session.config.option.verbose
    hook = session.config.hook
    session._initialpaths = set()
    session._initialparts = []
    session._notfound = []
    session.items = []
    for arg in redis_list:
        term.write(os.linesep)
        parts = session._parsearg(arg)
        session._initialparts.append(parts)
        session._initialpaths.add(parts[0])
        arg = "::".join(map(str, parts))
        session.trace("processing argument", arg)
        session.trace.root.indent += 1
        try:
            for x in session._collect(arg):
                items = session.genitems(x)
                new_items = []
                for item in items:
                    new_items.append(item)

                # HACK ATTACK: This little hack lets us remove the
                # 'collected' and 'collecting' messages while still
                # keeping the default verbosity for the rest of the
                # run...
                session.config.option.verbose = -1
                hook.pytest_collection_modifyitems(session=session,
                                                   config=session.config,
                                                   items=new_items)
                session.config.option.verbose = default_verbosity
                for item in new_items:
                    session.items.append(item)
                    _pytest.runner.pytest_runtest_protocol(item, None)
        except NoMatch:
            # we are inside a make_report hook so
            # we cannot directly pass through the exception
            raise pytest.UsageError("Could not find" + arg)
        session.trace.root.indent -= 1
    return session.items
Beispiel #5
0
def pytest_terminal_summary(terminalreporter: TerminalReporter, exitstatus: int, config: Config):
    yield
    revision = os.getenv("GITHUB_SHA", "local")
    platform = os.getenv("PLATFORM", "local")

    terminalreporter.section("Benchmark results", "-")

    result = []
    for test_report in terminalreporter.stats.get("passed", []):
        result_entry = []

        for _, recorded_property in test_report.user_properties:
            terminalreporter.write("{}.{}: ".format(test_report.head_line,
                                                    recorded_property["name"]))
            unit = recorded_property["unit"]
            value = recorded_property["value"]
            if unit == "MB":
                terminalreporter.write("{0:,.0f}".format(value), green=True)
            elif unit in ("s", "ms") and isinstance(value, float):
                terminalreporter.write("{0:,.3f}".format(value), green=True)
            elif isinstance(value, float):
                terminalreporter.write("{0:,.4f}".format(value), green=True)
            else:
                terminalreporter.write(str(value), green=True)
            terminalreporter.line(" {}".format(unit))

            result_entry.append(recorded_property)

        result.append({
            "suit": test_report.nodeid,
            "total_duration": test_report.duration,
            "data": result_entry,
        })

    out_dir = config.getoption("out_dir")
    if out_dir is None:
        warnings.warn("no out dir provided to store performance test results")
        return

    if not result:
        warnings.warn("no results to store (no passed test suites)")
        return

    get_out_path(Path(out_dir), revision=revision).write_text(
        json.dumps({
            "revision": revision, "platform": platform, "result": result
        }, indent=4))
Beispiel #6
0
def redis_test_generator(config, redis_connection, redis_list_key,
                         backup_list_key=None):
    """A generator that pops and returns test paths from the redis list key."""
    term = TerminalReporter(config)

    val = retrieve_test_from_redis(redis_connection,
                                   redis_list_key,
                                   backup_list_key)

    if val is None:
        term.write("No items in redis list '%s'\n" % redis_list_key)

    while val is not None:
        yield val
        val = retrieve_test_from_redis(redis_connection,
                                       redis_list_key,
                                       backup_list_key)
Beispiel #7
0
def pytest_terminal_summary(terminalreporter: TerminalReporter,
                            exitstatus: int, config):
    yield
    if hasattr(config, "all_confs"):
        terminalreporter.section("OCR Avg Confidences")
        terminalreporter.write("Conf.\tSimil.\tTest Explanation\n")
        terminalreporter.write("-" * 65 + "\n")
        for c in config.all_confs:
            terminalreporter.write(f"{c[0]:.1f}\t{c[1]:.2f}\t({c[2]})\n")
        terminalreporter.write("-" * 65 + "\n")
        conf_sum = sum([c[0] for c in config.all_confs])
        sim_sum = sum([c[1] for c in config.all_confs])
        count = len(config.all_confs)
        terminalreporter.write(
            f"{conf_sum/count:.2f}\t{sim_sum/count:.2f}\tMean\n")
        terminalreporter.write(f"{conf_sum:.2f}\t{sim_sum:.2f}\tSum\n")