Pytest 使用Pycharm右键直接运行测试脚本正常,控制台命令pytest运行收集不到用例无法正常测试 no tests ran in 0.01s

all.py脚本内容

sql 复制代码
import  pytest
if __name__ == '__main__':
    pytest.main(['-sv', './testcase','-n=3'])
    print('你好世界')

说明

这个文件我命名为all.py,内容如上,右键使用pycharm运行all.py时,testcase目录下的3个pytest测试文件的用例均正常运行,但是在控制台console中使用pytest all.py命令时,就报错收集不到用例,而使用pytest ./testcase又是正常的,非常奇怪,折腾了两个多小时

解决方案

控制台运行时,要使用python all.py指令即可正常进行测试,因为pytest会收集以test开头名称相关的测试用例,这里使用pytest all.py在控制台中直接运行all.py文件时找不到test开头或者_test结尾的相关用例,所以会有信息如上。不过IDE右键运行确实是正常的,研究了两个多小时没找到原因,暂时只是找到了方法

相关推荐
白云LDC1 天前
Android Studio新建Vecter asset一直显示Loading icons(转圈圈)的解决办法
android·ide·android studio
An_s1 天前
编辑器AI工具(vscode+claude)
ide·vscode·编辑器
SilentSamsara1 天前
闭包的本质:Python 如何捕获自由变量
开发语言·python·青少年编程·pycharm
secondyoung1 天前
VSCode设置显示空白字符
ide·vscode·编辑器
迷路爸爸1802 天前
VSCode / Cursor 中 LaTeX Workshop 的 settings.json 配置:编译与 SyncTeX 跳转
ide·vscode·json·latex
Lhan.zzZ2 天前
笔记_2026.4.28_004
c++·ide·笔记·qt
一帘忧梦3 天前
vscode 搭建stm32开发环境 +HAL 库
ide·vscode·编辑器
skiy3 天前
SpringBoot项目中读取resource目录下的文件(六种方法)
spring boot·python·pycharm
独隅3 天前
Visual Studio 2026 详细安装教程和配置指南
ide·visual studio
lifewange4 天前
Pycharm和IDEA中安装Cursor的方法
ide·pycharm·intellij-idea