A pytest plugin to collect test requirements from requirements marker.
Project description
pytest-collect-requirements
A pytest plugin to collect test requirements from tests marked with the @pytest.mark.requirements(...) marker.
This plugin allows you to specify requirements for your tests and collect them without executing the tests themselves as default behavior.
Features
- ✅ addoption
--collect-requirementsto collect requirements without running tests - ✅ addoption
--save-toto specify the output file path for collected requirements (default:logs/test_requirements.json) - ✅ addoption
--execute-teststo run tests after collecting requirements - ✅ Collect requirements from tests using the
@pytest.mark.requirements()marker - ✅ Flexible keyword arguments support for any requirement metadata (e.g., cloud instances, regions, resources)
- ✅ Automatic collection and store the requirements in json file
- ✅ Seamless integration with pytest's marker system
Installation
pip install pytest-collect-requirements
Usage Examples
Basic Usage
Mark your tests with the @pytest.mark.requirements() marker to specify infrastructure requirements:
import pytest
@pytest.mark.requirements(cloud_instance="c5.large", region="eu-west-1")
def test_my_feature():
assert 1 == 1
Collecting Requirements
Run pytest with the --collect-requirements flag to collect all requirements without executing tests:
pytest --collect-requirements
This will collect all requirements from tests marked with @pytest.mark.requirements() and store them in the pytest config for later use.
Multiple Requirements
You can mark multiple tests with different requirements:
import pytest
@pytest.mark.requirements(cloud_instance="c5.large", region="eu-west-1")
def test_requirements():
assert 1 == 1
@pytest.mark.requirements(cloud_instance="c5.small", region="eu-west-2")
def test_requirements2():
assert 1 == 1
Custom Requirement Parameters
The @pytest.mark.requirements() marker accepts any keyword arguments, allowing you to define custom requirement metadata:
import pytest
@pytest.mark.requirements(
cloud_instance="c5.large",
region="eu-west-1",
storage="100GB",
network="high-speed"
)
def test_with_custom_requirements():
assert 1 == 1
import pytest
from _pytest.fixtures import FixtureRequest
def requirements(cloud_instance: str, region: str) -> pytest.MarkDecorator:
return pytest.mark.requirements(
cloud_instance=cloud_instance,
region=region,
)
@requirements(
cloud_instance="c5.large",
region="eu-west-1",
)
def test_requirements_with_static_parameters(request: FixtureRequest):
assert request.config._selected_requirements[request.node.nodeid]['region'] == "eu-west-1"
🤝 Contributing
If you have a helpful tool, pattern, or improvement to suggest:
Fork the repo
Create a new branch
Submit a pull request
I welcome additions that promote clean, productive, and maintainable development.
🙏 Thanks
Thanks for exploring this repository!
Happy coding!
Project details
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_collect_requirements-1.0.0.tar.gz.
File metadata
- Download URL: pytest_collect_requirements-1.0.0.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47281fa75748d1dbc01ad1ec1c37a8be6b2607aff0871ce75847bf6a0b5793d6
|
|
| MD5 |
2c0917c4dbb34a8c229a3e5922137913
|
|
| BLAKE2b-256 |
35d03c51a373cd9aadc14ee868776a088ca7f3c3e542314a878807b0632ca92f
|
File details
Details for the file pytest_collect_requirements-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pytest_collect_requirements-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
810f306667abcc5947e677158565503c66485148d2b2d4c56b8b3a4e0dcf44b0
|
|
| MD5 |
bc758b5450f8810c08d7b75731d723a3
|
|
| BLAKE2b-256 |
307ee4a46f8d377e11d8c8ca1d1171ac3e666c761307c4a40286b69db07e1a38
|