在Debian上进行Python测试可按以下步骤操作:
sudo apt update && sudo apt upgrade -y
sudo apt install python3 python3-pip
python3 -m venv venv
source venv/bin/activate
pytest
或unittest
(Python标准库,无需额外安装):pip install pytest
tests
目录,编写测试脚本(以pytest
为例):# test_example.py
def test_addition():
assert 1 + 1 == 2
pytest
:在项目根目录执行pytest tests
unittest
:执行python -m unittest discover tests
OK
,失败会输出详细错误信息注:unittest
为Python内置框架,pytest
需额外安装,但功能更强大。