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 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-0.0.3.tar.gz (4.7 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.3-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for pytest_collect_requirements-0.0.3.tar.gz
Algorithm Hash digest
SHA256 0c4778cc7af809f33f535d0b90f14c42a630c2b05c5a71c123d56443c98b37b5
MD5 a08ea4a4fb651f84b093dfc8fc25b74b
BLAKE2b-256 0e9eba063fefe388fd01892e74064a1a3d39edfd9cd13e599ba4fb5db0cbb2af

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytest_collect_requirements-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 46a6b3ade0346fd0050dd95c649b5f50278f0d3112d9e41ea6b58ac617da84b3
MD5 3944a53ce5682bc29acef18ed807afe7
BLAKE2b-256 fdbb7f63e28f58bd52843334de2d4134f028f3d677424a7752b4ec82751c7551

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