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

相关推荐
2601_9622845017 小时前
安卓APP UI自动化测试:Python + UiAutomator2 + pytest + pytest-html
python·pytest·uiautomator2·ui自动化测试·安卓app
2601_9623008117 小时前
基于pytest的接口自动化测试:使用requests模块的实战项目与接口关联方法详解
接口自动化测试·测试用例·pytest·接口关联·requests模块
2601_9623008117 小时前
Python + Requests + Pytest + Excel + Allure:接口自动化测试项目实战
python·excel·pytest·allure·requests
2501_9159184117 小时前
在Windows10上使用VSCode和Code Runner搭建Swift开发环境详细步骤
ide·vscode·ios·objective-c·个人开发·swift·敏捷流程
墨白曦煜18 小时前
穿透 IDE 的障眼法:Git 四大工作区与核心数据流转解析
ide·git
泡泡鱼(敲代码中)1 天前
Python语法技术学习笔记
开发语言·笔记·python·学习·pycharm
郝学胜_神的一滴1 天前
Effective Python 条款 8: 同时遍历多组序列:zip 与 zip_longest 的实战避坑指南
python·pycharm
承渊政道1 天前
【Python编程—从入门到实践】(Python字典:从基础语义到现代工程实践)
开发语言·python·pycharm·字典·嵌套
11路没有终点2 天前
Pytest 安装、版本与第一个测试用例
测试用例·pytest
kqz20142 天前
Android Studio Commit 面板临时文件.gitignore
ide·android studio·intellij-idea