def _pytest(session, coverage, cmd_args):
    _create_ci_directories()
    env = {'CI_RUN': ('1' if CI_RUN else '0')}
    if IS_DARWIN:
        env['OBJC_DISABLE_INITIALIZE_FORK_SAFETY'] = 'YES'
    if CI_RUN:
        session.run('python', '-m', 'pytest', *(cmd_args + ['--collect-only', '-qqq']), env=env)
    try:
        if (coverage is True):
            _run_with_coverage(session, 'python', '-m', 'coverage', 'run', '-m', 'pytest', '--showlocals', *cmd_args, env=env)
        else:
            session.run('python', '-m', 'pytest', *cmd_args, env=env)
    except CommandFailed:
        raise
        session.log('Re-running failed tests')
        for (idx, parg) in enumerate(cmd_args):
            if parg.startswith('--junitxml='):
                cmd_args[idx] = parg.replace('.xml', '-rerun-failed.xml')
        cmd_args.append('--lf')
        if (coverage is True):
            _run_with_coverage(session, 'python', '-m', 'coverage', 'run', '-m', 'pytest', '--showlocals', *cmd_args)
        else:
            session.run('python', '-m', 'pytest', *cmd_args, env=env)
def _pytest(session, coverage, cmd_args):
    _create_ci_directories()
    env = {'CI_RUN': ('1' if CI_RUN else '0')}
    if IS_DARWIN:
        env['OBJC_DISABLE_INITIALIZE_FORK_SAFETY'] = 'YES'
    if CI_RUN:
        session.run('python', '-m', 'pytest', *(cmd_args + ['--collect-only', '-qqq']), env=env)
    try:
        if (coverage is True):
            _run_with_coverage(session, 'python', '-m', 'coverage', 'run', '-m', 'pytest', '--showlocals', *cmd_args, env=env)
        else:
            session.run('python', '-m', 'pytest', *cmd_args, env=env)
    except CommandFailed:
        raise
        session.log('Re-running failed tests')
        for (idx, parg) in enumerate(cmd_args):
            if parg.startswith('--junitxml='):
                cmd_args[idx] = parg.replace('.xml', '-rerun-failed.xml')
        cmd_args.append('--lf')
        if (coverage is True):
            _run_with_coverage(session, 'python', '-m', 'coverage', 'run', '-m', 'pytest', '--showlocals', *cmd_args)
        else:
            session.run('python', '-m', 'pytest', *cmd_args, env=env)