from clarabot_nano_tests.testing.process import pypopen_communicate


def start_core_expect_error(args, error, env=None, return_code=1, timeout=3, start_module="clarabot_nano"):
    try:
        with pypopen_communicate([start_module] + args, env=env) as pcom:
            assert pcom.subp.wait(timeout) == return_code
        assert pcom.err.find(error) >= 0, f"{error}\n{pcom.err}"
    except Exception:
        print("FAILED_SUBP_OUT", pcom.out)
        print("FAILED_SUBP_ERR", pcom.err)
        raise
