Skip to main content

pytest-lockable

Tests 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 . .

Metadata

Release files for pytest-lockable 0.11.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-lockable 0.11.0
File Size Uploaded
pytest_lockable-0.11.0.tar.gz 13.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-lockable 0.11.0
File Interpreter ABI Platform
pytest_lockable-0.11.0-py3-none-any.whl Python 3 none any Details

Total release size: 18.3 kB

Release files / pytest_lockable-0.11.0.tar.gz

Download URL pytest_lockable-0.11.0.tar.gz
Size 13.3 kB
Tags Source
SHA-256 checksum
How to use checksums
411e22937c1e80830cdea3c9409e59fa0aabf553dcf6bfa8ccf06ec6b4cab4b8
BLAKE2b-256 checksum
How to use checksums
41a90f8f4d33daff1aa3357812922fc49d14598d9ac261abedeb7e8f835d768a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.11

Release files / pytest_lockable-0.11.0-py3-none-any.whl

Download URL pytest_lockable-0.11.0-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d9068279a84adfb5b8d115e4cba2338ea25ed1fa2874af5d551a10a6049b7163
BLAKE2b-256 checksum
How to use checksums
f7016521b8cc326cdc5fedbc24ff916019083c07785908b4a54389bbf2bdb06a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.11

Release history Release notifications | RSS feed

This release

0.11.0 This release

2 release files

0.10.0

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.5

2 release files

0.7.4

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page