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

conftest.py:

pytest_plugins = ("lockable.plugin",)

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.7.4.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

pytest_lockable-0.7.4-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest-lockable-0.7.4.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.12

File hashes

Hashes for pytest-lockable-0.7.4.tar.gz
Algorithm Hash digest
SHA256 a6beb95fa3527e12d143b0a46d1a7eef66962db443299f756989ae74f92b96b7
MD5 8732bbd855d68053a3678fae582f1ec7
BLAKE2b-256 4cec458898447a37cb2a6f8bfcf4e8cb7378d243966d25aecdea863939465900

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytest_lockable-0.7.4-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.12

File hashes

Hashes for pytest_lockable-0.7.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b58de0bb8d6e7565bf6acc490db46ced545bf61c1562ca1a86aa18cea045cfd7
MD5 5278b76a25eae1d034be3a6581fc3153
BLAKE2b-256 199682665edf09de9f202c07dcb1b62d476aa97d9f8d2d75a4204d7175d8e031

See more details on using hashes here.

Supported by

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