Python Unittest: Open and wait until the program is closed

前端 未结 5 1436
醉酒成梦
醉酒成梦 2021-01-16 05:55

Currently I try to create an unit test which opens a file (with the corresponding application) and then the test-run should wait until the program is closed.



        
5条回答
  •  心在旅途
    2021-01-16 06:21

    os.startfile is, of course, completely non-blocking with no options to wait.

    I'd recommend using the subprocess module, calling the Windows "start" command to open the file with the associated object, which does the same thing as os.startfile, but allows you to wait for the process to finish.

    e.g.:

    subprocess.call(["start", my_file])
    

提交回复
热议问题