我的程序使用下面的代码生成一个警报/消息框。
import tkinter as tk
from tkinter import messagebox
root = tk.Tk()
root.withdraw()
messagebox.showwarning('End of Data', "You have reached the end of the data.")
我想对此代码运行一个简单的单元测试。我想断言消息框出现并且消息框中的文本是“您已到达数据末尾。”。也许像assert appears
and之类的东西assert message == "You have reached the end of the data."
。
理想情况下,我想使用 PyTest 来做到这一点,但是仍然非常感谢使用其他框架的解决方案。
(对于上下文,我使用的是 Python 3。)