from datetime import datetime


def make_test_run(
        testinstance,
        exec_date='',
        exec_time='',
        duration='0',
        status='Passed'
):
    """
    Create a RunInstance in QC.
    """
    run = testinstance.RunFactory.AddItem("Run {}".format(datetime.now()))
    run.Status = status
    run.SetField('RN_DURATION', duration)
    run.SetField('RN_EXECUTION_DATE', exec_date)
    run.SetField('RN_EXECUTION_TIME', exec_time)
    run.Post()
    run.Refresh()
    # do again, otherwise not showing in QC
    run.SetField('RN_EXECUTION_DATE', exec_date)
    run.SetField('RN_EXECUTION_TIME', exec_time)
    run.Post()
    run.Refresh()
    return run