pytest-base-url is a pytest plugin that provides a `base_url` fixture for testing web applications. It allows you to define a base URL, from which derived `host` and `port` fixtures are automatically available in your tests. The current version is 2.1.0, and releases are generally tied to `pytest` compatibility or new features as needed, without a fixed cadence.
pip install pytest-base-urlVerified import paths — ran on the pinned version, not inferred.
To quickly get started, first install the plugin. Then, configure your base URL in a `pytest.ini` file in your project's root directory under the `[pytest]` section. Finally, write your tests, making sure to declare `base_url`, `host`, or `port` as arguments in your test functions to utilize the injected fixtures.
Instead of `--base-url`, define the base URL in your `pytest.ini` file under the `[pytest]` section (e.g., `base_url = https://example.com/`) or directly within a custom `pytest_base_url` fixture in your `conftest.py`.
Always ensure your `base_url` in `pytest.ini` is a complete, valid URL including the scheme and a trailing slash if necessary for your application context (e.g., `https://api.example.com/`). Verify its value in tests using `print(base_url)` or assertions.
Ensure your `base_url` is consistently formatted. If a specific port is needed, include it explicitly in `base_url` (e.g., `https://example.com:8080/`). The `port` fixture will return `None` if no port is specified in the URL.