網(wǎng)站首頁 編程語言 正文
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
相關(guān)推薦
- 2022-05-17 ubuntu解決虛擬機(jī)Ubuntu連接不了網(wǎng)絡(luò)(親測(cè))
- 2022-06-02 關(guān)于docker?registry使用詳解_docker
- 2023-02-27 詳解C++?STL模擬實(shí)現(xiàn)list_C 語言
- 2022-07-18 Linux 文件內(nèi)容瀏覽;cut命令;uniq命令;sort命令;tr命令;
- 2022-10-03 react實(shí)現(xiàn)數(shù)據(jù)監(jiān)聽方式_React
- 2022-06-17 mongodb?數(shù)據(jù)塊的遷移流程分析_MongoDB
- 2022-04-20 C++的多態(tài)和虛函數(shù)你真的了解嗎_C 語言
- 2022-08-10 go?字符串修改的操作代碼_Golang
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支