Skip to main content

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.


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)
  • ✅ Collect requirements from tests using the @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 @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 @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-0.0.2.tar.gz (4.6 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-0.0.2-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for pytest_collect_requirements-0.0.2.tar.gz
Algorithm Hash digest
SHA256 f58cc050f5809e8d6a1ff2f913a5a16d13ef9c311d9b835971b8eee6e3ed1552
MD5 6d0f677ae0a368550b521537c1c8c7cc
BLAKE2b-256 13590414ba5d5b7a5ee07ebc1edf5a97b38453c59b0f8c7ff7ead6f20c0e1652

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytest_collect_requirements-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 234e3c0f08462daa1185af13cf9258d24d487f043ebbc07852d5105d34114ad1
MD5 358def666fbb575338ba0adfc694cf12
BLAKE2b-256 f24c8102548e36cd107c3ab850f6e8937d642c8cc559fcec1f3e073ae0182f55

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