## PyCharm Setup for Pytest 執行環境準備 + 安裝 Miniconda + 安裝 PyCharm + 安裝 Pytest --- ### 安裝 Miniconda + [Windows 安裝說明](https://conda.io/projects/conda/en/latest/user-guide/install/windows.html) + [macOS 安裝說明](https://conda.io/projects/conda/en/latest/user-guide/install/macos.html) + [Linux(Ubuntu) 安裝說明](https://conda.io/projects/conda/en/latest/user-guide/install/linux.html) --- ### 安裝 PyCharm + [下載 PyCharm](https://www.jetbrains.com/pycharm/download/) --- ### 測試 Code with me + 跟你的分組成員一起測試 Code with me, 了解如何 remote pair. 影片從 12:35 開始 demo {%youtube dY7qQNJlUiM %} --- ### PyCharm Setup for Pytest(1/10) 建立新專案 ![](https://i.imgur.com/e8kto4M.png =750x) --- ### PyCharm Setup for Pytest(2/10) 設定新專案名稱:"pytestlab" ![](https://i.imgur.com/XJwKJx6.png =750x) --- ### PyCharm Setup for Pytest(3/10) 設定 default test runner ![](https://i.imgur.com/D3LRaUY.png =800x) --- ### PyCharm Setup for Pytest(4/10) 設定 default test runner (cont.) ![](https://i.imgur.com/BSTKH8R.png =800x) --- ### PyCharm Setup for Pytest(5/10) Create test file. ![](https://i.imgur.com/3x39C3d.png =800x) --- ### PyCharm Setup for Pytest(6/10) 建立 PyCharm 專案後,再 Terminal 用 pip 安裝 ```bash pip install pytest ``` ##### Pytest 官方文件:https://docs.pytest.org/ --- ### PyCharm Setup for Pytest(7/10) Install pytest. ![](https://i.imgur.com/vIoWOeW.png =800x) --- ### PyCharm Setup for Pytest(8/10) 測試 Pytest 是否能正確執行 ```python= 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 ![](https://i.imgur.com/5tTQ1il.png =800x) --- ### PyCharm Setup for Pytest(10/10) test pass!!! ![](https://i.imgur.com/E8cVpzx.png =800x)
{"metaMigratedAt":"2023-06-16T03:48:44.948Z","metaMigratedFrom":"YAML","title":"PyCharm 及 Pytest 環境","breaks":true,"slideOptions":"{\"transition\":\"slide\",\"showNotes\":false,\"incremental\":true}","contributors":"[{\"id\":\"89a0ce2f-418b-48fd-9391-f1e7c3fdd209\",\"add\":2145,\"del\":152}]"}
    683 views