pytest-exception-script
The goal of this pytest plugin is to allow quick and easy testing of your application's resiliency. This is accomplished by creating exception scripts / scenarios which allow you to inject exceptions into your code execution without having to repeatedly set-up tests.
This won't work for applications that have multiple processes, but should work with threads (need to do more testing). Under the hood it's just abusing monkeypatch.
Structure
Scripts can be written in YAML or TOML.
Each script / scenario (these will be used interchangeably below) consists of multiple acts, each of which can have multiple actions. Scenario is successful and complete if every act in it is complete.
To have your script detected: make sure it starts with chaos_ and is a toml or yaml file. It will get auto-discovered by pytest, or you can call pytest directly against the file.
Examples of config files:
Using yaml
entry-point: tests.fake_app_success.factory
next-point: tests.fake_app_success.process_data
acts:
- tests.fake_app_success.get_data:
- exc: KeyError, "Error in act I"
next-point:
tests.fake_app_success.unused_method:
- exc: OSError, "Custom message passed"
- tests.fake_app_success.get_data:
- exc: KeyError
Using toml
entry-point="tests.fake_app_success.factory"
next-point="tests.fake_app_success.process_data"
[[act]]
[[act."tests.fake_app_success.get_data"]]
exc="KeyError"
next-point="tests.fake_app_success.process_data"
[[act]]
[[act."tests.fake_app_success.get_data"]]
exc="KeyError"
[[act]]
[[act."tests.fake_app_success.get_data"]]
exc="KeyError"
What's happening here?
entry-point should be a factory for your application that takes no parameters.
next-point - can be specified globally, per act, or both. Once this method gets called script will move on to the next act.
acts - list of acts each of which consists of actors. Each Actor is a method and an exception that it will throw if called during execution.
exc - exception to raise.
So factory will be loaded and started, upon which first act starts. Every time when get_data will get called KeyError will be raised. With either a default or a custom message. Once next-point gets called next act starts. Once next-point of the last act is called the application terminates (hopefully) and all the tests get marked as complete.
Metadata
Release files for pytest-exception-script 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytest-exception-script-0.1.0.tar.gz | 10.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_exception_script-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 35.0 kB
Release files / pytest-exception-script-0.1.0.tar.gz
| Download URL | pytest-exception-script-0.1.0.tar.gz |
|---|---|
| Size | 10.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5869158f7e7d85a8f11beb33e6994b0907963bc174bf74410911a3c347a06e49
|
|
BLAKE2b-256 checksum How to use checksums |
9d73e0a7dd00ebe9e034a0a7f57fa0afaf7c9222e55ed07e87c22cf90a6562c6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
|
Release files / pytest_exception_script-0.1.0-py3-none-any.whl
| Download URL | pytest_exception_script-0.1.0-py3-none-any.whl |
|---|---|
| Size | 24.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1eede3f3c0373ad0f7ab33748237d1f857b4e35a2d9253ff0914fb5dafd5046a
|
|
BLAKE2b-256 checksum How to use checksums |
7f34cc56b5f515ff4f1e2298f5db477289497be96bae25a5da2c3ad0b0a95036
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
|