簡體   English   中英

python中的測試函數,需要從用戶那里獲取輸入並打印輸出,使用pycharm和pytest

[英]testing function in python that need to get input from user and print the output, using pycharm and pytest

我在 python 3 中編寫了代碼,並想使用 Pytest 框架為我的代碼編寫測試。 我有一個函數(主函數)從用戶那里獲取輸入(一個文件名),處理它並將結果打印到屏幕上(答案可以是對的或錯的)。 如何編寫自己輸入數據的測試函數(用於主輸入)並檢查打印到控制台的內容? (我使用 Pycharm)

def main():
    file_input = input(str('path to your file here'))
    with open(file_input, mode="r") as f:
        for line in f:
            reader = line.split()
            # Convert to boolean <-- Not working?
            flag = bool(reader[0])

            if flag:
                print('flag == True')
            else:
                print('flag == False')


if __name__ == '__main__':
    main()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM