我正在用“Python 速成課程”這本書學習 Python。
現在我已經到了第 11 章“測驗你的代碼”,我有一個問題。作者在書中留下了以下注釋:
當測驗用例運行時,Python 會在每個單元測驗完成時列印一個字符。通過的測驗列印一個點,導致錯誤的測驗列印 E,導致斷言失敗的測驗列印 F。這就是為什么您會在第一行看到不同數量的點和字符的原因運行測驗用例時的輸出。如果測驗用例因為包含許多單元測驗而需要很長時間運行,您可以查看這些結果以了解通過了多少測驗。
我使用 Pycharm,當我測驗某些東西時,Pycharm 不會提示作者所說的點。
如果你能幫我解決我的問題,我將不勝感激
我也會把我在這里運行的代碼留下,因為我認為它可能會有所幫助
from survey import AnonymousSurvey
class TestAnonymousSurvey(unittest.TestCase):
"""Tests for the class AnonymousSurvey."""
def setUp(self):
"""
Create a survey and a set of responses for use in all test methods
"""
question = "What language did you first learn?"
self.my_survey = AnonymousSurvey(question)
self.responses = ['Arabic', 'Farsi', "English"]
def test_store_single_response(self):
"""Test that a single response gets stored correctly."""
self.my_survey.store_response(self.responses[0])
self.assertIn(self.responses[0], self.my_survey.responses)
def test_store_three_responses(self):
"""Test that a set of three responses is stored correctly."""
for response in self.responses:
self.my_survey.store_response(response)
for response in self.responses:
self.assertIn(response, self.my_survey.responses)```
**Thanks!**
uj5u.com熱心網友回復:
默認情況下,unittest使用的默認測驗運行器將TextTestRunner其進度輸出列印到stderr,因此不會被 PyCharm 捕獲。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/365017.html
