Skip to main content

Generate test cases for shell scripts

Project description

PyShellTest

Build/Test

Generate python test cases for shell commands based on simple configuration. Allows you to seemlessly test commands that need to be run from a shell but within the python testing framework.

We all need to write more tests and including outside commands allows for more coverage. For instance:

  • Add linkchecker to your integ runs for a django project
  • Ensure tools in bin/ have a --help

Installation

TODO

Integration

Add this to you test files where you see fit:

generator = PyShellTestGenerator.from_json("sample-config.json")
test_class = generator.generate()

You can then run your tests like you would normally and PyShellTest will generate tests based on your conifg.json

python -m pytest tests/

Configuration

See sample-config.json as well as tests/test-config.json

Example configuration for a command:

{
    "the-command-name": {
        # The command to run
        "command": ["path/to/script.sh"], 
        
        # How long to wait before timing out
        "timeout": 30, 
        
        # Print the output of the ocmmand to stdout
        "print_output": true,
        
        # Expect this in stdout, fail otherwise
        "stdout_contains": "bar" 
          
        # Expect this in stderr, fail otherwise
        "stderr_contains": "bar"
        
        # Set this dict if you expect errors from the command
        "error": { 
            # Expect an error
            "expect": true, 
            
            # Expect an error with this class
            "error_class": "FileNotFoundError"
        },
    }
}

Development

Testing

How to test this project

poetry run python -m pytest 

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

pyshelltest-0.6-6dev0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file pyshelltest-0.6-6dev0.tar.gz.

File metadata

  • Download URL: pyshelltest-0.6-6dev0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.0a2 CPython/3.8.10 Linux/5.11.0-1027-azure

File hashes

Hashes for pyshelltest-0.6-6dev0.tar.gz
Algorithm Hash digest
SHA256 50ba705bf91ec6010723ae3ec0c3400b605a9be7760f1b15d5aa92e6a3f76586
MD5 51b2972dbf87da21d9efd7418c4cd3a1
BLAKE2b-256 e0934e3292af3e1e24b3431537244d6ad1db05f82b1e11cf97bb1324b3a82a86

See more details on using hashes here.

File details

Details for the file pyshelltest-0.6_6dev0-py3-none-any.whl.

File metadata

  • Download URL: pyshelltest-0.6_6dev0-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags:
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.0a2 CPython/3.8.10 Linux/5.11.0-1027-azure

File hashes

Hashes for pyshelltest-0.6_6dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 021c68677854c0f233dc92b616cea5507e6bfc55a3229527beae9dbfb7086e3c
MD5 c14fe11ca1e8373265326aa3eef6d74e
BLAKE2b-256 812b658f6b08b61e88f4a1d8cd69beb073a4bca2c4c2a702545e350c8b0c5b59

See more details on using hashes here.

Supported by

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