py.test的Pyramid服务器固定工具
项目描述
py.test的Pyramid服务器固定工具。服务器默认为会话作用域,并在子进程中运行在临时目录中,因此是一个“真实”的服务器,您可以将其指向Selenium webdriver。
安装
使用您喜欢的包管理器进行安装
pip install pytest-pyramid-server
# or..
easy_install pytest-pyramid-server
在测试或conftest.py中显式启用固定工具(使用setuptools入口点时不需要)
pytest_plugins = ['pytest_pyramid_server']
配置
此固定工具在其当前工作目录中搜索配置文件“testing.ini”。cwd中的所有.ini文件都将复制到临时目录中,以便paster风格的配置链仍然可以正常工作。例如
my-pyramid-app/ src/ # Project code is in here setup.py # Project setup.py development.ini # Development settings production.ini # Production settings testing.ini # Testing settings, will be used if tests # are invoked using 'py.test' from this # directory
示例
这是一个简单的测试用例,展示了主要功能。
def test_pyramid_server(pyramid_server):
# This is the http://{host}:{port} of the running server. It will attempt to resolve
# to externally accessable IPs so a web browser can access it.
assert pyramid_server.uri.startswith('http')
# GET a document from the server.
assert pyramid_server.get('/orders/macbooks', as_json=True) == {'id-1234': 'MPB-15inch'}
# POST a document to the server.
assert pyramid_server.post('/login', 'guest:password123').response_code == 200
# ``path.py`` path object to the running config file
assert pyramid_server.working_config.endswith('testing.ini')
PyramidServer 类
使用默认的 pyramid_server py.test 适配器对于大多数用例已经足够好了,但是您可能希望对服务器配置有更细粒度的控制。为了实现这一点,您可以直接使用底层的服务器类 - 这是一个 pytest-server-fixture 框架的实现,因此它充当上下文管理器。
from pytest_pyramid import PyramidTestServer
def test_custom_server():
with PyramidTestServer(
# You can specify you own config directory and name
config_dir='/my/config',
config_fileme='my_testing.ini',
# You can set arbitrary config variables in the constructor
extra_config_vars={'my_config_section': {'my_dbname: 'foo',
'my_dbpass: 'bar'}}
) as server:
assert not server.dead
assert 'my_dbname = foo' in server.working_config.text()
# Server should now be dead
assert server.dead
pytest-webdriver 和 PageObjects 集成
pytest-webdriver 插件将检测此插件是否激活,并将其默认基本 URL 设置为运行服务器的 URL。当使用 Page Objects 时,这是一种避免在浏览器测试中进行大量字符串操作的好方法。
from page_objects import PageObject, PageElement
class LoginPage(PageObject):
username = PageElement(id_='username')
password = PageElement(name='password')
login = PageElement(css='input[type="submit"]')
def test_login_page(webdriver, pyramid_server):
page = LoginPage(webdriver)
page.login.click()
page.get('/foo/bar')
assert webdriver.getCurrentUrl() == pyramid_server.uri + '/foo/bar'
变更日志
1.7.0
所有:支持 pytest >= 4.0.0
所有:支持 Python 3.7
pytest-server-fixtures:如果您的机器上未定义主机,则默认为 localhost
pytest-server-fixture:由于上游 API 变更,将 rethinkdb 固定在 < 2.4.0
pytest-verbose-parametrize:添加对改进的标记基础设施的支持
pytest-verbose-parametrize:修复集成测试以支持 pytest >= 4.1.0
pytest-virtualenv:添加 virtualenv 作为安装要求。修复 #122
pytest-webdriver:使用 getfixturevalue 修复 RemovedInPytest4Warning
circleci:通过跳过对没有推送访问权限的开发者的 coverall 提交来修复检查
wheels:生成可同时安装 python 2.x 和 3.x 的通用 wheels
dist:删除对构建和分发 *.egg 文件的支持
VagrantFile:默认安装 python 3.7 并初始化 python 3.7
修复使用“logger.warning()”函数的 DeprecationWarning 警告
1.6.2 (2019-02-21)
pytest-server-fixtures:如果调用 kill(),则抑制堆栈跟踪
pytest-server-fixtures:修复 TestServerV2 中的随机端口逻辑
1.6.1 (2019-02-12)
pytest-server-fixtures:修复在服务器未启动时尝试访问主机名时的异常
1.6.0 (2019-02-12)
pytest-server-fixtures:添加之前已删除的 TestServerV2.kill() 函数
pytest-profiling:在集成测试中将 more-itertools==5.0.0 固定,因为这是一个仅限 PY3 的版本
1.5.1 (2019-01-24)
pytest-verbose-parametrize:修复使用 @pytest.mark.parametrize 时的 Unicode 参数
1.5.0 (2019-01-23)
pytest-server-fixtures:将 postgres 适配器和其测试设置为可选,如所有其他适配器
pytest-server-fixtures:撤销对 pymongo 弃用警告的修复,因为这将破坏与 pymongo 3.6.0 的兼容性
pytest-server-fixtures:在 httpd 中删除对 RHEL5 的支持
1.4.1 (2019-01-18)
pytest-server-fixtures:现在,在 ENV 中指定的服务器适配器二进制路径仅影响 'thread' 服务器类
1.4.0 (2019-01-15)
修复 Simple HTTP 服务器适配器中的 python 3 兼容性
修复 pytest-profiling 中的损坏测试
将 pytest 固定在 < 4.0.0,直到修复所有弃用警告。
pytest-webdriver:用无头 Google Chrome 替换已弃用的 phantomjs。
将 Vagrantfile 添加到项目中,以便使测试环境可移植。
将 .editorconfig 文件添加到项目中。
pytest-server-fixtures:添加具有 Docker 和 Kubernetes 支持的 TestServerV2。
pytest-server-fixtures:修复了 MinioServer 在使用后未清理的问题。
pytest-server-fixtures:修复了调用 pymongo 时的弃用警告。
pytest-server-fixtures:在 MongoTestServer 拆卸时关闭 pymongo 客户端。
pytest-server-fixtures:将 Mongo、Redis 和 RethinkDB 升级到 TestServerV2。
coveralls:修复损坏的 coveralls
1.3.1 (2018-06-28)
使用 pymongo list_database_names() 代替已弃用的 database_names(),添加 pymongo >= 3.6.0 依赖项
1.3.0 (2017-11-17)
修复了 teardown 为 None 时的工作空间删除问题
修复了 pytest-listener 中的根记录器压缩问题
添加了 S3 Minio 适配器(感谢 Gavin Bisesi)
添加了 Postgres 适配器(感谢 Gavin Bisesi)
使用 requests 对服务器适配器的 http get 进行请求,因为它正确处理重定向和代理
1.2.12 (2017-8-1)
修复了缓存短暂主机名的回归,一些客户端依赖于此。现在这是可选的。
1.2.11 (2017-7-21)
修复OSX绑定到非法本地IP范围的错误(感谢Gavin Bisesi)
pytest-profiling的设置和Py3k修复(感谢xoviat)
当保留本地IP主机时,我们不再尝试绑定端口5000,因为有人可能将其绑定到0.0.0.0
修复了在本地venv未激活时源gprof2dot的#46错误
1.2.10 (2017-2-23)
在pytest-webdriver中处理自定义Pytest测试项
1.2.9 (2017-2-23)
将用户名添加到mongo服务器固定tempdir路径中,以防止在共享多用户文件系统上发生冲突
1.2.8 (2017-2-21)
在shutil.run.run_as_main中返回函数结果
1.2.7 (2017-2-20)
对older versions of path.py的更多处理
允许在pytest-virtualenv中传递virtualenv参数
1.2.6 (2017-2-16 )
更新devpi服务器设置以支持devpi-server >= 2.0
随机端口选择的改进
默认情况下,HTTPD服务器现在绑定到0.0.0.0以帮助Selenium-style测试
更新mongodb服务器参数以支持mongodb >= 3.2
修复mongodb固定配置和改进启动逻辑的错误
添加模块范围的mongodb固定项
对older versions of path.py的处理
修复了#40错误,其中chdir的测试会导致pytest-profiling崩溃
1.2.5 (2016-12-09)
对服务器运行程序主机和端口生成的改进,现在支持随机本地IP
修复RethinkDB固定配置的错误
1.2.4 (2016-11-14)
修复pymongo额外依赖的错误
修复pytest-virtualenv的Windows兼容性错误(感谢Jean-Christophe Fillion-Robin的PR)
修复pytest-shutil.cmdline.get_real_python_executable的符号链接处理错误
1.2.3 (2016-11-7)
提高Mongo固定启动检查的容错性
1.2.2 (2016-10-27)
大多数模块的Python 3兼容性
修复了废弃的Path.py导入(感谢Bryan Moscon)
修复了pytest-profiling中的废弃的多重调用(感谢Paul van der Linden的PR)
添加devpi-server固定项以创建每个测试函数的索引
添加缺失的许可文件
拆分httpd服务器固定配置,以便子类可以更容易地覆盖加载的模块
将“preserve_sys_path”参数添加到TestServer基类,该参数将当前的python sys.path导出到子进程中。
更新httpd、redis和jenkins运行时参数和路径,以符合当前的Ubuntu规范
在拆除工作区时忽略错误,以避免“shutil.rmtree”实现中的竞态条件
1.2.1 (2016-3-1)
修复了pytest-verbose-parametrize以支持最新的py.test版本
1.2.0 (2016-2-19)
新插件:git存储库固定项
1.1.1 (2016-2-16)
pytest-profiling改进:在.prof文件中转义非法字符(感谢Aarni Koskela的PR)
1.1.0 (2016-2-15)
新插件:devpi服务器固定项
pytest-profiling改进:过长的.prof文件被保存为测试名称的短散列(感谢Vladimir Lagunov的PR)
出于安全原因,将workspace.run()的默认行为更改为不使用子shell
修正virtualenv.run()方法以处理与父方法workspace.run()相同的参数
从virtualenv参数中删除废弃的“–distribute”
1.0.1 (2015-12-23)
包装错误修复
1.0.0 (2015-12-21)
首次公开发布
项目详情
下载文件
为您的平台下载文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。
源分布
构建版本
pytest-pyramid-server-1.7.0.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 28ced2e7b943c59610491ada0b07abc814b15cd3e14e8cdd676b3d2f66bfb905 |
|
MD5 | 0f7624d6c7a6200a5a08de2d5d99bced |
|
BLAKE2b-256 | 65e8e57b9dff704553c95a29dc152d1e0e49cfcdea779bd0f5efc498bc22ccf0 |
pytest_pyramid_server-1.7.0-py3.6.egg 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 749bc193edcbecacfde37ec6be535333635d5937b712b2ac8fd7cf34b357726c |
|
MD5 | 2042835077c0deb1d666cff9d8270c7d |
|
BLAKE2b-256 | 0b075948ba963bd3c74ce868c97e171859b0468b76a5330734ebe8b5e2a04608 |
pytest_pyramid_server-1.7.0-py2.py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 617509244fbe80571092b59ee564b0fcf66f2f89877ffa4eea325f24f68f3b0c |
|
MD5 | 89b90953e42629f46f3e356b11e3f239 |
|
BLAKE2b-256 | 0c5cba04a2c0fde6a54efaeeffea4405d572b5e99290b06020b6fef30cf2539e |
pytest_pyramid_server-1.7.0-py2.7.egg 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 9fa9ff183465a1740ed43ffae51805863c1089c68f3eddc435ee0a8ded2b0ce3 |
|
MD5 | 9178c015db0b3962a33c5579c9203215 |
|
BLAKE2b-256 | 095cd71fc6da9d559ccc4fa22d5b8f6b7ff4fbac2ab85d6eb5795b39af6840ac |