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右键运行确实是正常的,研究了两个多小时没找到原因,暂时只是找到了方法

相关推荐
司悠5 小时前
【解决在vscode里开服务器登录codeX后发消息会一直reconnecting】
服务器·ide·vscode
Allenliu _Andy10 小时前
2026 最新版|免登录适配国内网络 Claude Code 终端版安装配置教程(Windows)
ide·chatgpt·openai·ai编程·claude code
CTA量化套保11 小时前
Jupyter Notebook 反复运行天勤策略内存涨:close 与内核习惯
ide·人工智能·python·jupyter
Esaka_Forever17 小时前
PyCharm 社区版无法识别 .db 文件类型
数据库·ide·pycharm
小明_GLC19 小时前
Opencode Go接入Claude Code
pycharm·claude code·open code
AD钙奶-lalala2 天前
Android Studio新建项目默认不使用Compose模版
android·ide·android studio
专注VB编程开发20年2 天前
开发VS2026插件最佳方案:老式VSIX EnvDTE
ide·c#·visual studio
专注VB编程开发20年2 天前
VS2026最新ide插件VisualStudio.Extensibility进程外 OOP 新模型
ide·c#·visual studio
弹简特2 天前
【接口自动化】01-pytest详解、pytest执行逻辑、pytest参数、配置文件和pytest标记
自动化·pytest
香辣西红柿炒蛋2 天前
pytest框架介绍
python·pytest