Skip to main content

A pytest plugin to collect test requirements from requirements marker.

Project description

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!

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

pytest_collect_requirements-1.0.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_collect_requirements-1.0.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file pytest_collect_requirements-1.0.0.tar.gz.

File metadata

File hashes

Hashes for pytest_collect_requirements-1.0.0.tar.gz
Algorithm Hash digest
SHA256 47281fa75748d1dbc01ad1ec1c37a8be6b2607aff0871ce75847bf6a0b5793d6
MD5 2c0917c4dbb34a8c229a3e5922137913
BLAKE2b-256 35d03c51a373cd9aadc14ee868776a088ca7f3c3e542314a878807b0632ca92f

See more details on using hashes here.

File details

Details for the file pytest_collect_requirements-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_collect_requirements-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 810f306667abcc5947e677158565503c66485148d2b2d4c56b8b3a4e0dcf44b0
MD5 bc758b5450f8810c08d7b75731d723a3
BLAKE2b-256 307ee4a46f8d377e11d8c8ca1d1171ac3e666c761307c4a40286b69db07e1a38

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page