Skip to main content

PyPI version Python Development Status Maintenance PyPI License


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-requirements to collect requirements without running tests
  • ✅ addoption --save-to to specify the output file path for collected requirements (default: logs/test_requirements.json)
  • ✅ addoption --execute-tests to 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!

Metadata

Release files for pytest-collect-requirements 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-collect-requirements 1.1.1
File Size Uploaded Provenance
pytest_collect_requirements-1.1.1.tar.gz 4.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-collect-requirements 1.1.1
File Interpreter ABI Platform
pytest_collect_requirements-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 10.7 kB

Release files / pytest_collect_requirements-1.1.1.tar.gz

Download URL pytest_collect_requirements-1.1.1.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
7354b05e51f6f16788365e1de01e05949c80663d76ac066f1fae5b2705cdb914
BLAKE2b-256 checksum
How to use checksums
60f6c1fde161be51f4d1ea8e34565a0b673f81b978524f9b3e026916bf4187a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / pytest_collect_requirements-1.1.1-py3-none-any.whl

Download URL pytest_collect_requirements-1.1.1-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
66ae67fd3723ea712f7800cd7094f052013bf75eeac735d3131d993dd01fdfe7
BLAKE2b-256 checksum
How to use checksums
a8866a894edb79745a63f03dbf3b37fbf5449743e8d6418191713ccab1579a9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Security for pytest-collect-requirements 1.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page