日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

【報錯:No module named pytest】

作者:EVE ???? 更新時間: 2022-09-25 編程語言

No module named pytest

問題:

寫了一個pytest的配置文件,想在命令行通過pytest啟動配置文件來運行測試用例。報錯:No module named pytest

排查:

pytest我肯定是安裝過了,但是為什么還會找不到該模塊。我打開pycharm的Python Interpreter查看確實是有的
在這里插入圖片描述
于是在終端輸入:

which python3

在這里插入圖片描述

原因

系統默認解釋器和pycharm選擇的解釋器不是同一個,系統默認的那個python解釋器里沒有安裝pytest
在這里插入圖片描述

解決

系統默認python3解釋器是在/usr/bin/python3下,我回到pycharm——Preferences——Python Interpreter——右上角設置——+號——Vitualenv Environment——New Environment——Base Interpreter選擇在該/usr/bin/python3目錄下的python解釋器。
在這里插入圖片描述
發現果然沒有pytest
在這里插入圖片描述
點擊左上角+號,搜索pytest點擊install可成功安裝。Terminal中輸入:
pytest可成功運行
在這里插入圖片描述
test_add_01.py:

def add(x, y):
    return x + y


class TestAdd:

    def setup(self):
        print("測試用例開始執行")

    def test_add_01(self):
        result = add(1, 2)
        assert result == 3

    def test_add_02(self):
        result = add(2, 2)
        assert result == 5

    def teardown(self):
        print("測試用例執行結束")

原文鏈接:https://blog.csdn.net/simpleness_/article/details/126673713

欄目分類
最近更新