Skip to main content

lockable resource plugin for pytest

Project description

pytest-lockable

CircleCI PyPI version Coverage Status

pytest plugin for lockable resources.

Replacement for Jenkins lockable -plugin. Locking is implemented using <resource-id>.pid files and is released automatically.

Resources are automatically released when pytest ends.

Resources are described in json file as array of objects. Each object has some mandatory fields but can contains any other as well. Required fields are: id, online, hostname.

Example resources.json

[
  {
    "id": "1234",
    "online": true,
    "hostname": "localhost",
    "os": "Android"
  }
]

id should be unique for each resources. online describes if resource are available for allocator. Set this false if you don't want to allocate resource. hostname is used to select suitable resource by running host.

Usage:

pytest --allocation_hostname localhost -s --allocation_requirements os=Android my_test

installation

Requires: python 3.7<

pip install pytest-lockable

integrations

pytest-lockable integrates pytest-metadata - when resource is reserved and pytest-metadata plugin are in use metadata will be generated from resource json with resource_ -prefixes. e.g. resource_id=<id>. Same dictionary are also recorded to testsuite property using record_testsuite_property -method.

Usage

Custom options:

--allocation_hostname=<hostname>, default=<os-hostname>  Allocation host
--allocation_requirements=<requirements>                 Resource requirements to be allocate
--allocation_timeout=<timeout>, default=10               Allocation timeout in seconds
--allocation_resource_list_file=<filename>, default=resources.json 
                                                         Available resorces list
--allocation_lock_folder=<folder>, default=<os-tmp-path> allocation lockfiles folder

<requirements> can be json-string or key-value pairs. requirements have to match available resources to make allocation possible. Key-value pairs example: key=value&key2=value2

Example:

Use shared lockable resource

def test_example(lockable_resource):
    """ Simple test """
    print(f'Testing with resource: {lockable_resource}')

Allocate lockable resource during test with given requirements

def test_example(lockable):
    """ Simple test """
    with lockable.auto_lock({"my": "requirements"}) as allocation:
        print(f'Testing with resource#: {allocation.resource_id}')

See example test. Usage:

cd example
pytest --allocation_hostname localhost -s --allocation_lock_folder . .

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-lockable-0.10.0.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

pytest_lockable-0.10.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file pytest-lockable-0.10.0.tar.gz.

File metadata

  • Download URL: pytest-lockable-0.10.0.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.12

File hashes

Hashes for pytest-lockable-0.10.0.tar.gz
Algorithm Hash digest
SHA256 b6f56fdd31c59f4860be7adb86ace547faab5c5b30ee58730e8eea2ee59ab875
MD5 ff102acf2ee5518b0b69c751f70e0572
BLAKE2b-256 4426b41927a73bf275a00358fde84f2b4b55fcceb57681db9f2c295f8006a86c

See more details on using hashes here.

File details

Details for the file pytest_lockable-0.10.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_lockable-0.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d80e073efb7708547c95a9c3816b1f25ff98d9ed37aa518412285945d8f2b217
MD5 234c3837c2c0f48ac95c26c8e32002c3
BLAKE2b-256 f02ddd7af6fb2781281cb6bbd730cd47adbcf870649e654067a86029769a4f2b

See more details on using hashes here.

Supported by

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