快速构建vscode pytest 开发测试环境

如果不想用 heavy 的pycharm

vscode 也是1个很好的选择

安装python SDK

复制代码
pacman -S python
[gateman@manjaro-x13 tmp]$ pacman -Q python
python 3.11.8-1

安装Vscode

很多中方法

bash 复制代码
yay -S visual-studio-code-bin
[gateman@manjaro-x13 tmp]$ pacman -Q | grep -i visual
visual-studio-code-bin 1.88.1-1

安装微软python 插件

一个microsoft python 就够来, 另外两个是依赖, 关联安装

新建1个空项目文件夹

我们就命名为python1 吧

bash 复制代码
[gateman@manjaro-x13 tmp]$ mkdir -p python1
[gateman@manjaro-x13 tmp]$ ls
python1

用vscode 打开这个文件夹

在welcome 页面新建 项目基本的虚拟环境

在项目内创建test folder

并在里面创建1个test类, 命名规则 test_xxx.py

配置vscode pytest 环境

配置之后可能会有error, 重新打开vscode, 就会见到pytest 已经配好

配置pytest configuration

在项目根目录创建1个pytest.ini

bash 复制代码
[pytest]
addopts = -s

这样pytest 就可以输出console里的输出

测试pytest

可以见到有hello world 输出

构建requirement.txt

执行

bash 复制代码
pip freeze > requirement.txt
bash 复制代码
(.venv) [gateman@manjaro-x13 python1]$ pip freeze > requirement.txt
(.venv) [gateman@manjaro-x13 python1]$ ls
main.py  pytest.ini  requirement.txt  test
(.venv) [gateman@manjaro-x13 python1]$ ls -l
total 12
-rw-r--r-- 1 gateman gateman    0 May  4 01:44 main.py
-rw-r--r-- 1 gateman gateman   21 May  4 01:53 pytest.ini
-rw-r--r-- 1 gateman gateman   61 May  4 01:56 requirement.txt
drwxr-xr-x 3 gateman gateman 4096 May  4 01:49 test
(.venv) [gateman@manjaro-x13 python1]$ cat requirement.txt 
iniconfig==2.0.0
packaging==24.0
pluggy==1.5.0
pytest==8.2.0

好了到一步配置基本完成, 下一步可以配置log 框架的什么的了, 建议这里先checkin 代码。

相关推荐
何中应6 小时前
IDEA实用快捷键
java·ide·intellij-idea
周周记笔记1 天前
PyCharm的初始设置
ide·python·pycharm
周周记笔记1 天前
Pycharm详解:高效Python开发的首选IDE
ide·python·pycharm
Maer091 天前
VSCode中Kilo Code插件集成终端输出中文乱码问题解决
ide·vscode·编辑器
我的xiaodoujiao1 天前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 22--数据驱动--参数化处理 Json 文件
python·学习·测试工具·pytest
半夏微凉半夏殇1 天前
VSCode Remote-SSH:无缝远程开发完全指南
ide·vscode·ssh
名剑走天下2 天前
VScode中模拟lvgl运行环境配置
ide·vscode·编辑器·lvgll
deng-c-f2 天前
配置(4):VScode c/c++编译环境的配置:c_cpp_properties.json
c语言·c++·vscode
漂流幻境2 天前
IntelliJ IDEA的Terminal中执行ping命令时遇到的“No route to host“问题
java·ide·intellij-idea
BUG?不,是彩蛋!2 天前
IntelliJ IDEA从安装到使用:零基础完整指南
java·ide·intellij-idea