nginx fixture for pytest - iplweb临时分支
项目描述
pytest-nginx
pytest-nginx是一个pytest插件,允许您测试需要与完整功能的Web服务器进行通信的代码。可以创建自定义fixture来管理服务器根目录的内容。
使用方法
该插件包含一个fixture
nginx_proc - 会话作用域的fixture,管理nginx守护进程,具有为提供静态文件的基本配置。
nginx_php_proc - 会话作用域的fixture,管理nginx守护进程和php-fpm守护进程,两者配置为协同工作。
所有fixture都采用管理服务器根目录的名称。在 simplest 情况下,它是由tmpdir_factory内置fixture管理的空临时目录。
from pytest_nginx import factories
@pytest.fixture(scope="session")
def nginx_server_root(tmpdir_factory):
return tmpdir_factory.mktemp("nginx-server-root")
nginx_proc = factories.nginx_proc("nginx_server_root")
要管理提供的内容,您可以在nginx_proc之上创建额外的模块或函数作用域的fixture。
@pytest.fixture(scope="module")
def nginx_hello_world(nginx_proc):
f = open(os.path.join(nginx_proc.server_root, "index.html"), "w")
f.write("Hello world! This is pytest-nginx serving on host {}, port {}."
.format(nginx_proc.host, nginx_proc.port))
f.close()
return nginx_proc
配置
您可以通过以下三种方式定义您的设置:使用fixture工厂参数、使用命令行选项和使用pytest.ini配置选项。这些设置按照以下顺序处理
Fixture工厂参数
命令行选项
pytest.ini 配置选项
Fixture 工厂参数 |
命令行选项 |
pytest.ini 选项 |
默认 |
---|---|---|---|
主机 |
–nginx-host |
nginx_host |
127.0.0.1 |
端口 |
–nginx-port |
nginx_port |
随机 |
nginx_exec |
–nginx-exec |
nginx_exec |
nginx |
nginx_params |
–nginx-params |
nginx_params |
“” |
nginx_config_template |
–nginx-config-template |
nginx_config_template |
自动生成 |
php_fpm_exec |
–php-fpm-exec |
php_fpm_exec |
php-fpm |
php_fpm_params |
–php-fpm-params |
php_fpm_params |
“” |
php_fpm_config_template |
–php-fpm-config-template |
php_fpm_config_template |
自动生成 |
显示如何指定端口号的示例
将其作为工厂函数的参数传递
nginx_proc = factories.nginx_proc(port=8888)
在运行 pytest 时使用 --nginx-port 命令行选项
pytest ./tests --nginx-port=8888
将 nginx_port 选项添加到 pytest.ini 文件中
[pytest] nginx_port =
8888
项目详情
pytest_nginx_iplweb-1.1.1-py3-none-any.whl 的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 4e3c6004d412264464ab1bf1e8b1253d050c93bafd87c2f458cbc56680de143e |
|
MD5 | a6964db7b6476cbdc5575ab3336af811 |
|
BLAKE2b-256 | 89f2089d513f50f70b4061790aa396cf1b07dcf9702bf465bbe9cb8aa35dd02c |