最早我在目錄下建立一個test.py
寫了簡單的代碼然後就是執行式會發生錯誤
然後我想說可能是test.py這個名稱會不會是跟pycharm系統中的關鍵名稱衝突了
所以就改成test_rq.py
但是結果好像也一樣
程式碼如下:
for i in range(49,1,-1):
print(i)
執行輸出如下:
C:\ProgramData\Anaconda3\python.exe "C:/Program Files/JetBrains/PyCharm Community Edition 2022.2.2/plugins/python-ce/helpers/pycharm/_jb_pytest_runner.py" --path C:\Users\FANMO4F\PycharmProjects\pythonProject2\test_rq.py
Testing started at 上午 07:53 ...
C:\Program Files\JetBrains\PyCharm Community Edition 2022.2.2\plugins\python-ce\helpers\pycharm\_jb_pytest_runner.py:8: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
from pkg_resources import iter_entry_points
Launching pytest with arguments C:\Users\FANMO4F\PycharmProjects\pythonProject2\test_rq.py --no-header --no-summary -q in C:\Users\FANMO4F\PycharmProjects\pythonProject2
============================= test session starts =============================
collecting ... collected 0 items
============================ no tests ran in 0.01s ============================
进程已结束,退出代码5
空套件
pycharm 遇到 test 開頭的檔案會預設要跑測試,而測試的撰寫是有一定格式的,你新增 python 檔案的時候就有 unittest 形式可以選擇了。
import unittest
class MyTestCase(unittest.TestCase):
def test_something(self):
self.assertEqual(True, False) # add assertion here
if __name__ == '__main__':
unittest.main()
pycharm 遇到 unittest 格式的檔案只會跑 test_
開頭的 method 而已。
執行前要確認右上角的config用的是Python而不是test