fastiot package
FastIoT Library
Subpackages
Submodules
fastiot.testlib module
Helpers to make writing tests easier
- fastiot.testlib.populate_test_env(deployment_name='')[source]
Populates the local environment with test env vars from the test integration deployment.
It will import the .env-file from build dir and raise an error if not available. It will then overwrite these values from the .env-file within deployment dir for more robustness because sometimes the developer forgets to rebuild the config. Overwriting the env values with the deployment dir should solve it.
- Parameters:
deployment_name (
Optional
[str
]) – Optionally specify a different deployment to be used instead of the integration test
- async fastiot.testlib.init_background_process(service, startup_time=0.2)[source]
Helper to start a FastIoT Service as background task. This may help if your service already has many internal tasks and needs to act as a server for your unit or integration tests.
Be sure to stop your service afterward like in the following example:
>>> from fastiot_sample_services.producer.producer_module import ExampleProducerService >>> from fastiot.testlib import init_background_process >>> >>> background_process = await init_background_process(service=ExampleProducerService) >>> # Do some stuff with the service >>> background_process.terminate() >>> # Or if you want to be really sure to have a stopped service: >>> try: >>> background_process.kill() >>> except ProcessLookupError: >>> pass
- Parameters:
service (
object
) – The Service inheriting fromfastiot.core.service.FastIoTService
(without ())startup_time (
float
) – The time to wait for the service to become ready, defaults to 0.2 seconds
- Returns:
A Process
- class fastiot.testlib.BackgroundProcess(service, startup_time=0.2, stop_time=0.05)[source]
Class to help with FastIoT Services as background process for tests.
This class is especially made to be used in async with contexts and behaves similar to
fastiot.testlib.init_background_process()
but saves you from manually exiting the service:>>> from fastiot_sample_services.producer.producer_module import ExampleProducerService >>> from fastiot.testlib import BackgroundProcess >>> >>> async with BackgroundProcess(ExampleProducerService, startup_time=0.03): >>> pass # Do some stuff with the service >>> # Outside the context the service will be terminated and killed
- __init__(service, startup_time=0.2, stop_time=0.05)[source]
Constructor
- Parameters:
service (
object
) – The Service inheriting fromfastiot.core.service.FastIoTService
(without ())startup_time (
float
) – The time to wait for the service to become ready, defaults to 0.2 seconds