Repository: pact-foundation/pact-python (language: python)

Issue:
Update `hatch run test` to support arguments
### Have you read the Contributing Guidelines on issues?

- [X] I have read the [Contributing Guidelines on issues](https://github.com/pact-foundation/pact-python/blob/main/CONTRIBUTING.md#issues).

### Description

Hatch scripts have a placeholder for additional arguments. For example, if wanting to run only a subset of all tests, it should be possible to do:

```sh
hatch run test tests/v3
```

Hatch supports this by looking for `{arg}` or `{arg:<default>}` in the script's string.

While this was included in the lint rules, it was unfortunately omitted from the test rules.

Completion of this requires:

- [x] Fixing the `test` script in the default environment
- [x] Fixing the `test` script in the test environment matrix

### Has this been requested on Canny?

_No response_

### Motivation

This issue was identified in https://github.com/pact-foundation/pact-python/pull/395#issuecomment-1749097768.

### Have you tried building it?

_No response_

### Self-service

- [X] I'd be willing to contribute this feature to Pact Python myself.


Discussion / hints:

Fix patch:
diff --git a/pyproject.toml b/pyproject.toml
index e7f2d38254..2fff1c8256 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -103,10 +103,10 @@ features           = ["dev"]
 extra-dependencies = ["hatchling", "packaging", "requests"]
 
 [tool.hatch.envs.default.scripts]
-lint = ["black --check --diff {args:.}", "ruff {args:.}", "mypy {args:.}"]
-test = "pytest --cov-config=pyproject.toml --cov=pact --cov=tests tests/"
-example = "pytest examples/ {args}"
-all = ["lint", "test", "example"]
+lint    = ["black --check --diff {args:.}", "ruff {args:.}", "mypy {args:.}"]
+test    = "pytest {args:tests/}"
+example = "pytest {args:examples/}"
+all     = ["lint", "test", "example"]
 
 # Test environment for running unit tests. This automatically tests against all
 # supported Python versions.
@@ -117,16 +117,26 @@ features = ["test"]
 python = ["3.8", "3.9", "3.10", "3.11"]
 
 [tool.hatch.envs.test.scripts]
-test = "pytest --cov-config=pyproject.toml --cov=pact --cov=tests tests/"
-example = "pytest examples/ {args}"
-all = ["test", "example"]
+test    = "pytest {args:tests/}"
+example = "pytest {args:examples/}"
+all     = ["test", "example"]
 
 ################################################################################
 ## PyTest Configuration
 ################################################################################
 
 [tool.pytest.ini_options]
-addopts = ["--import-mode=importlib"]
+addopts = [
+  "--import-mode=importlib",
+  "--cov-config=pyproject.toml",
+  "--cov=pact",
+]
+filterwarnings = [
+  "ignore::DeprecationWarning:pact",
+  "ignore::DeprecationWarning:tests",
+  "ignore::PendingDeprecationWarning:pact",
+  "ignore::PendingDeprecationWarning:tests",
+]
 
 ################################################################################
 ## Coverage


Test patch:
diff --git a/conftest.py b/conftest.py
new file mode 100644
index 0000000000..b6bf257ad2
--- /dev/null
+++ b/conftest.py
@@ -0,0 +1,20 @@
+"""
+Global Pytest configuration.
+
+This file is used to define global Pytest configuration. In this case, we use it
+to define additional command line options to customise the examples.
+"""
+
+import pytest
+
+
+def pytest_addoption(parser: pytest.Parser) -> None:
+    """Define additional command lines to customise the examples."""
+    parser.addoption(
+        "--broker-url",
+        help=(
+            "The URL of the broker to use. If this option has been given, the container"
+            " will _not_ be started."
+        ),
+        type=str,
+    )
diff --git a/examples/conftest.py b/examples/conftest.py
index aa1de61b13..eba8ffc73e 100644
--- a/examples/conftest.py
+++ b/examples/conftest.py
@@ -21,18 +21,6 @@
 EXAMPLE_DIR = Path(__file__).parent.resolve()
 
 
-def pytest_addoption(parser: pytest.Parser) -> None:
-    """Define additional command lines to customise the examples."""
-    parser.addoption(
-        "--broker-url",
-        help=(
-            "The URL of the broker to use. If this option has been given, the container"
-            " will _not_ be started."
-        ),
-        type=str,
-    )
-
-
 @pytest.fixture(scope="session")
 def broker(request: pytest.FixtureRequest) -> Generator[URL, Any, None]:
     """