【Pytest笔记】pytest-pythonpath插件的使用
来源:互联网 发布:福建祥游网络 编辑:程序博客网 时间:2024/05/17 03:40
pytest-pythonpath
This is a py.test plugin for adding to the PYTHONPATH from the pytests.ini file before tests run.
这句话的意思是说,我们可以测试中所需要加入到PYTHONPATH中的路径,写到pytest.ini中。这样再运行测试之前,pytest.ini中的路径会自动添加到PYTHONPATH变量里面。
Installation
Install with pip::
pip install pytest-pythonpath
Uninstall with pip::
pip uninstall pytest-pythonpath
Usage
Add a line in your pytest.ini file with a key of python_paths
and provide a space seperated list of pathsyou want inserted to the beginning of the PYTHONPATH before any tests run:
[pytest]python_paths = your/path/apps your/path/libs
Once this is added to your pytest.ini, you can use the py.test command as you normally would.上面是举了一个栗子,说如果想把your/path/apps和your/path/libs加入到PYTHONPATH中,需要把它们用空格隔开赋值给pytest.ini里面的python_paths。这样在测试执行之前,就会把your/path/apps和your/path/libs加入到PYTHONPATH中了。我们的测试中需要导入your/path/apps和your/path/libs中的模块时,就不至于发生improtError了。
验证
Github上有源码https://github.com/bigsassy/pytest-pythonpath
我们把源码下载下来,用py.test执行test_pythonpath.py,将运行正常。
但是,把源码中的pytest.ini给个其他名字,用py.test执行test_pythonpath.py.会发生improtError错误。这是因为我们没有把pytest.ini中的test_path/apps 和test_path/libs 导入到PYTHONPATH中。所以我们的test_pythonpath.py文件中将提示找不到所要导入的模块。说明,pytest.ini文件生效了。
- 【Pytest笔记】pytest-pythonpath插件的使用
- 使用pytest
- 【Pytest】pytest的基本设置
- pytest学习笔记
- pytest的plugin
- pytest的fixture
- pytest的fixture
- 【Pytest】pytest断言
- pytest fixture
- pytest使用说明
- 谭子pytest学习笔记(1)
- 说说使用nose、noes2、pytest感受
- 加速你的py.test, pytest-dist
- 关于pytest的简单用法(一)
- python里面Nose和pytest的区别
- 【Pytest】python单元测试框架pytest简介
- pytest相关问题解析
- pytest skip函数
- eclipse的xhtml文件,JSF标签无法自动提示的问题
- Oracle 11g密码过期问题
- linux 学习笔记 — 压缩命令
- 一个实现了ViewPart和EditroPart的简单RCP例子
- Driver 成本
- 【Pytest笔记】pytest-pythonpath插件的使用
- 第一题
- import com.sun.image.codec.jpeg.JPEGCodec不通过 找不到包
- 移动HTML5页面 head标签内都写点啥
- Android自动化测试 - MonkeyRunner(一)介绍
- OkHttp使用教程
- TOMCAT服务器配置域名
- ios开发常用知识点练习之记事本(一)
- adb 和 shell、Logcat 常用命令