pytest-nginx
pytest-nginx is a pytest plugin, that allows you to test code, which requires communicating with a full-fledged web server. Custom fixtures can be made which manage the content of the server root directory.
Usage
The plugin contains one fixture:
nginx_proc - session scoped fixture, which manages the nginx daemon with the most basic configuration for serving static files.
nginx_php_proc - session scoped fixture, which manages the nginx daemon and the php-fpm daemon, both configured to work together.
All fixtures take the name of a fixture managing the server root directory. In the simplest case it is an empty temporary directory managed with the tmpdir_factory built-in 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")
To manage the served content, you can create additional module or function-scoped fixtures on top of nginx_proc:
@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
Configuration
You can define your settings in three ways: with fixture factory arguments, with command line options and with pytest.ini configuration options. These settings are handled in the following order:
Fixture factory arguments
Command line options
pytest.ini configuration options
Fixture factory argument |
Command line option |
pytest.ini option |
Default |
|---|---|---|---|
host |
–nginx-host |
nginx_host |
127.0.0.1 |
port |
–nginx-port |
nginx_port |
random |
nginx_exec |
–nginx-exec |
nginx_exec |
nginx |
nginx_params |
–nginx-params |
nginx_params |
“” |
nginx_config_template |
–nginx-config-template |
nginx_config_template |
auto-generated |
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 |
auto-generated |
Examples showing how to specify the port number:
Pass it as an argument to the factory function:
nginx_proc = factories.nginx_proc(port=8888)Use the --nginx-port command line option when running pytest:
pytest ./tests --nginx-port=8888Add the nginx_port option to the pytest.ini file:
[pytest] nginx_port = 8888
Metadata
Release files for pytest-nginx 1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytest_nginx-1.2-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for pytest_nginx-1.2-py2.py3-none-any.whl |
Release files / pytest_nginx-1.2-py2.py3-none-any.whl
| Download URL | pytest_nginx-1.2-py2.py3-none-any.whl |
|---|---|
| Size | 19.1 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
b1e587507bdf6b90a1dc9bc7a5dbdce5b730b1920de6cbe61be19dcf0b875148
|
|
BLAKE2b-256 checksum How to use checksums |
9be36ca41e90d0b24cd2f2dce8a5e73e9e29fb301f01b593828b10de3a98e3c8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.3
|
Security for pytest-nginx 1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.