A pytest plugin that allows you to inject arguments into fixtures and parametrized tests using pytest command-line options.
Project description
pytest-inject
pytest-inject is a pytest plugin that allows you to inject arguments into fixtures and parametrized tests using pytest command-line options, effectively transforming your existing test suite into a set of dynamic debugging tools, without the need to modify or copy any test code.
pytest-inject is the solution when you temporarily modify tests to debug your application, or when your debugging scripts are based on existing tests.
Installation
You can install pytest-inject via pip:
pip install pytest-inject
Usage Docs
pytest-inject provides main command-line options:
-
--inject-jsonAllows you to inject arguments using a JSON string or a path to a JSON file.
Usage with JSON string:
pytest --inject-json '{"my_arg": "my_value", "count": 42}'
Usage with JSON file:
pytest --inject-json path/to/injection.json
-
--inject-dictAllows you to inject arguments using a Python dictionary defined in a file, or a callable that returns a dictionary. This is useful for injecting complex objects that cannot be represented in JSON.
Format:
path/to/file.py::variable_or_functionExample
injection_data.py:def get_data(): return {"complex_obj": SomeClass(), "timestamp": 123456789} data_dict = {"simple_arg": "value"}
Usage:
# Use a variable pytest --inject-dict injection_data.py::data_dict # Use a function pytest --inject-dict injection_data.py::get_data
-
--inject-allow-dupBy default, pytest-inject automatically removes duplicate parameter sets created by the injection. This process also re-indexes the parameter sets and removes their IDs. Use this flag to disable this behavior if you want to preserve the original parameter set indexes and IDs, or if you specifically need the duplicate test cases resulting from the injection.
Usage:
pytest "tests/test.py::test_my_app::[my_id]" --inject-json '{"arg": "val"}' --inject-allow-dup
Contributions
Contributions in the form of bug reports, feature requests, and pull requests are most welcome!
Development Installation
To install the project for development purposes:
-
Clone the repository:
git clone https://github.com/yourusername/pytest-inject.git cd pytest-inject
-
Install dependencies (assuming you are using a virtual environment):
pip install -e .
Or if you are using
hatch:hatch env create
Running Tests
To run the project's own tests after installing for development, execute pytest from the project root pointing to the
tests/ directory:
pytest tests/
Or if you are using hatch:
hatch test
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_inject-0.1.0.tar.gz.
File metadata
- Download URL: pytest_inject-0.1.0.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a754c4edf8795979cc45d131de8cf53bb1bbdda5ef50329e081b80015518f92c
|
|
| MD5 |
4630a45fac31510ece69051a1d61ddcb
|
|
| BLAKE2b-256 |
e4d481f1ad2bfc51d493076063e517b15fe78f32114ce095921d3e3185d6e01b
|
Provenance
The following attestation bundles were made for pytest_inject-0.1.0.tar.gz:
Publisher:
ci.yaml on liad-inon/pytest-inject
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_inject-0.1.0.tar.gz -
Subject digest:
a754c4edf8795979cc45d131de8cf53bb1bbdda5ef50329e081b80015518f92c - Sigstore transparency entry: 725015258
- Sigstore integration time:
-
Permalink:
liad-inon/pytest-inject@e16a21c4946dd35d360571fa5e49a49d9a125de7 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/liad-inon
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yaml@e16a21c4946dd35d360571fa5e49a49d9a125de7 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pytest_inject-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pytest_inject-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ded63c8e4b9fc270638111f50436c7d880543908e99d275e38cd176e94c35efa
|
|
| MD5 |
0f99cdf66d545dd177250007b3b21c44
|
|
| BLAKE2b-256 |
fe444746e75a5c56d9f3f3214a15e2b36fd3d0f938839c08b11a094bdc6740f6
|
Provenance
The following attestation bundles were made for pytest_inject-0.1.0-py3-none-any.whl:
Publisher:
ci.yaml on liad-inon/pytest-inject
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_inject-0.1.0-py3-none-any.whl -
Subject digest:
ded63c8e4b9fc270638111f50436c7d880543908e99d275e38cd176e94c35efa - Sigstore transparency entry: 725015264
- Sigstore integration time:
-
Permalink:
liad-inon/pytest-inject@e16a21c4946dd35d360571fa5e49a49d9a125de7 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/liad-inon
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yaml@e16a21c4946dd35d360571fa5e49a49d9a125de7 -
Trigger Event:
release
-
Statement type: