Skip to main content

Walk your code through exception script to check it's resiliency to failures.

Project description

Plugin Tests

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.

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-exception-script-0.1.0.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

pytest_exception_script-0.1.0-py3-none-any.whl (24.3 kB view details)

Uploaded Python 3

File details

Details for the file pytest-exception-script-0.1.0.tar.gz.

File metadata

  • Download URL: pytest-exception-script-0.1.0.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for pytest-exception-script-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5869158f7e7d85a8f11beb33e6994b0907963bc174bf74410911a3c347a06e49
MD5 9daddcc1abbff0493b4fab44d7fd1617
BLAKE2b-256 9d73e0a7dd00ebe9e034a0a7f57fa0afaf7c9222e55ed07e87c22cf90a6562c6

See more details on using hashes here.

File details

Details for the file pytest_exception_script-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pytest_exception_script-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 24.3 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for pytest_exception_script-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1eede3f3c0373ad0f7ab33748237d1f857b4e35a2d9253ff0914fb5dafd5046a
MD5 c5cbd04686e90511ecec0d7a4b795ebd
BLAKE2b-256 7f34cc56b5f515ff4f1e2298f5db477289497be96bae25a5da2c3ad0b0a95036

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