網站首頁 編程語言 正文
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
相關推薦
- 2022-07-06 Python?dataframe如何設置index_python
- 2022-07-07 WCF的異常處理_C#教程
- 2022-09-23 Go語言fmt.Sprintf格式化輸出的語法與實例_Golang
- 2023-11-26 XMLHttpRequest對象的Get請求和Post請求的用法
- 2022-10-23 Go語言數據結構之希爾排序示例詳解_Golang
- 2022-11-05 Android?TabLayout?自定義樣式及使用詳解_Android
- 2022-09-08 Pandas如何將Timestamp轉為datetime類型_python
- 2022-07-08 python中的type,元類,類,對象用法_python
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支