Registry / testing / pytest-base-url

pytest-base-url

JSON →
library2.1.0pypypi✓ verified 27d ago

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-url
INSTALL
IMPORT
SIG · PYTEST-BASE-URL
P
pytest-base-url
testingpythonv2.1.0
Install
3.5s avg
Import
Disk
33MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 34.4MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.5s · import 0.000s · 35MB
33MB installed
● package 33MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

base_url fixture
def test_my_endpoint(base_url, host, port):
pytest-base-url primarily provides fixtures ('base_url', 'host', 'port') that are automatically discovered and injected into your tests by the pytest framework. You do not import these fixtures directly using `from ... import ...` statements in your test files.

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.

# pytest.ini # [pytest] # base_url = https://api.example.com:8080/v1/ # test_example.py def test_api_endpoint(base_url, host, port): assert base_url == "https://api.example.com:8080/v1/" assert host == "api.example.com" assert port == "8080"
pytest --version
Debug
Known issues
breakingThe `--base-url` command-line option was removed in version 2.0.0. This significantly changes how the base URL is configured.
fix
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`.
affects: >=2.0.0
gotchaForgetting to configure `base_url` or misconfiguring it (e.g., missing `http://` or `https://` schema, incorrect port, or trailing slash issues) can lead to unexpected test failures.
fix
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.
affects: All versions
gotchaThe `host` and `port` fixtures are derived directly from `base_url`. If your `base_url` is missing a port or has an invalid format, `host` and `port` might not be correctly extracted.
fix
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.
affects: All versions
Upgrade
Version history
2.1.0latest on PyPI · released Jan 31, 2024
Audit
Dependencies
pytestrequiredCore testing framework, required for the plugin to function.
Agent activity
9 hits · last 30 days
node
8
Resources
pytest-base-url — pip install pytest-base-url · libregistry