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

學(xué)無先后,達(dá)者為師

網(wǎng)站首頁 編程語言 正文

【報(bào)錯(cuò):No module named pytest】

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

No module named pytest

問題:

寫了一個(gè)pytest的配置文件,想在命令行通過pytest啟動(dòng)配置文件來運(yùn)行測(cè)試用例。報(bào)錯(cuò):No module named pytest

排查:

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

which python3

在這里插入圖片描述

原因

系統(tǒng)默認(rèn)解釋器和pycharm選擇的解釋器不是同一個(gè),系統(tǒng)默認(rèn)的那個(gè)python解釋器里沒有安裝pytest
在這里插入圖片描述

解決

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

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


class TestAdd:

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

    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("測(cè)試用例執(zhí)行結(jié)束")

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

欄目分類
最近更新