快速构建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 代码。

相关推荐
cliffordl1 小时前
vscode 环境搭建
ide·vscode·编辑器
JANGHIGH1 小时前
VSCode引用Eigen库无法识别问题解决
ide·vscode·编辑器
我就是全世界3 小时前
开源集成开发环境搭建之VSCode启动Jupyter Notebook
ide·vscode·jupyter
科研小白_d.s13 小时前
vscode配置c/c++环境
c语言·c++·vscode
程序猿进阶20 小时前
如何在 Visual Studio Code 中反编译具有正确行号的 Java 类?
java·ide·vscode·算法·面试·职场和发展·架构
猿饵块20 小时前
vscode
ide·vscode·编辑器
XXX-1721 小时前
1.pytest基础知识(默认的测试用例的规则以及基础应用)
软件测试·pytest
大数据界Olu1 天前
bug | pycharm社区版无sciview解决办法
ide·python·pycharm
千寻简1 天前
Cursor免费 GPT-4 IDE 工具的保姆级使用教程
java·运维·ide·ai
我是一颗小小的螺丝钉1 天前
idea插件推荐之Cool Request
java·ide·intellij-idea