{"id":1664,"library":"pytest-base-url","title":"pytest-base-url plugin","description":"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.","status":"active","version":"2.1.0","language":"en","source_language":"en","source_url":"https://github.com/pytest-dev/pytest-base-url","tags":["pytest","plugin","testing","url","http","fixtures"],"install":[{"cmd":"pip install pytest-base-url","lang":"bash","label":"Install plugin"}],"dependencies":[{"reason":"Core testing framework, required for the plugin to function.","package":"pytest"}],"imports":[{"note":"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.","symbol":"base_url fixture","correct":"def test_my_endpoint(base_url, host, port):"}],"quickstart":{"code":"# pytest.ini\n# [pytest]\n# base_url = https://api.example.com:8080/v1/\n\n# test_example.py\ndef test_api_endpoint(base_url, host, port):\n    assert base_url == \"https://api.example.com:8080/v1/\"\n    assert host == \"api.example.com\"\n    assert port == \"8080\"","lang":"python","description":"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."},"warnings":[{"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`.","message":"The `--base-url` command-line option was removed in version 2.0.0. This significantly changes how the base URL is configured.","severity":"breaking","affected_versions":">=2.0.0"},{"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.","message":"Forgetting 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}