PyCharm Setup for Pytest 執行環境準備

  • 安裝 Miniconda
  • 安裝 PyCharm
  • 安裝 Pytest

安裝 Miniconda


安裝 PyCharm


測試 Code with me

  • 跟你的分組成員一起測試 Code with me, 了解如何 remote pair. 影片從 12:35 開始 demo
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

PyCharm Setup for Pytest(1/10)

建立新專案


PyCharm Setup for Pytest(2/10)

設定新專案名稱:"pytestlab"


PyCharm Setup for Pytest(3/10)

設定 default test runner


PyCharm Setup for Pytest(4/10)

設定 default test runner (cont.)


PyCharm Setup for Pytest(5/10)

Create test file.


PyCharm Setup for Pytest(6/10)

建立 PyCharm 專案後,再 Terminal 用 pip 安裝

pip install pytest
Pytest 官方文件:https://docs.pytest.org/

PyCharm Setup for Pytest(7/10)

Install pytest.


PyCharm Setup for Pytest(8/10)

測試 Pytest 是否能正確執行

import math def test_sqrt(): num = 25 assert math.sqrt(num) == 5 def test_square(): num = 7 assert 7 * 7 == 49 def test_equality(): # assert 10 == 11 # 10 assert 10 != 11 # 10

PyCharm Setup for Pytest(9/10)

執行 Pytest


PyCharm Setup for Pytest(10/10)

test pass!!!

Select a repo