Exemplo n.º 1
0
def remove_disabled_tests(session, config, items):
    """Remove all tests that are not defined in the config file"""
    enabled_tests = get_enabled_tests(config.getoption("tests_config"))
    for item in list(items):
        if item.nodeid.split("[")[0] not in enabled_tests:
            if get_xdist_worker_id(session) in ["master", "gw0"]:
                # log only in master process to avoid duplicate log entries
                logging.warning(
                    "Skipping test %s because not defined in config",
                    item.nodeid)
            items.remove(item)
Exemplo n.º 2
0
def pytest_sessionstart(session):
    """Workaround for https://github.com/pytest-dev/pytest/issues/7767

    remove if resolved and set autouse=True for record_testsuite_timestamp_xml fixture
    """
    if get_xdist_worker_id(session) == 'master':
        if session.config.pluginmanager.hasplugin('junitxml'):
            xml = session.config._store.get(xml_key, None)
            if xml:
                xml.add_global_property(
                    'start_time', datetime.datetime.utcnow().strftime(FMT_XUNIT_TIME)
                )
Exemplo n.º 3
0
def _log_collected_tests(session):
    from xdist import get_xdist_worker_id

    # Write collected tests in a single worker
    # get_xdist_worker_id returns the id of the current worker ('gw0', 'gw1', etc) or 'master'
    if get_xdist_worker_id(session) in ["master", "gw0"]:
        collected_tests = list(map(lambda item: item.nodeid, session.items))
        logging.info(
            "Collected tests in regions %s (total=%d):\n%s",
            session.config.getoption("regions") or get_all_regions(session.config.getoption("tests_config")),
            len(session.items),
            json.dumps(collected_tests, indent=2),
        )
        out_dir = session.config.getoption("output_dir")
        with open(f"{out_dir}/collected_tests.txt", "a") as out_f:
            out_f.write("\n".join(collected_tests))
            out_f.write("\n")
Exemplo n.º 4
0
 def test_get_xdist_worker_id(self, fake_request):
     assert xdist.get_xdist_worker_id(fake_request) == "gw5"
     del fake_request.config.workerinput
     assert xdist.get_xdist_worker_id(fake_request) == "master"