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

pip install pyshelltest

Integration

Add this to you test files where you see fit:

generator = PyShellTestGenerator.from_json("sample-config.json")
generator = PyShellTestGenerator.from_toml("sample-config.toml")
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/ as well as tests/test-config.toml

Toml config

Example configuration for a command:

[[command]]
 name = "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
    [command.error] 
    # Expect an error
    expect = true
    
    # Expect an error with this class
    error_class = "FileNotFoundError"

Json config

Example configuration for a command:

{
    "command": [
         {
            "_comment":  "# The command name",
            "name": "the-command-name",
            
            "_comment":  "# The command to run",
            "command": ["path/to/script.sh"], 
            
            "_comment":  "# How long to wait before timing out",
            "timeout": 30, 
            
            "_comment":  "# Print the output of the command to stdout",
            "print_output": true,
            
            "_comment":  "# Expect this in stdout, fail otherwise",
            "stdout_contains": "bar" ,
              
            "_comment":  "# Expect this in stderr, fail otherwise",
            "stderr_contains": "bar",
            
            "_comment":  "# Set this dict if you expect errors from the command",
            "error": { 
                "_comment":  "# Expect an error",
                "expect": true,
                
                "_comment":  "# 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.8.1-1dev0.tar.gz (5.3 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.8.1-1dev0.tar.gz.

File metadata

  • Download URL: pyshelltest-0.8.1-1dev0.tar.gz
  • Upload date:
  • Size: 5.3 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.8.1-1dev0.tar.gz
Algorithm Hash digest
SHA256 0323a56b4c05f3bcc145de97cdcdf7615fa9828eb5a2d26d90e5000e5d12bb1e
MD5 e3c4d293b668a918ac94b53b78d20422
BLAKE2b-256 f59a95e825b608eee30dda1acfe3f8b2d7e396ee764793f817b6e0dc6b2ac948

See more details on using hashes here.

File details

Details for the file pyshelltest-0.8.1_1dev0-py3-none-any.whl.

File metadata

  • Download URL: pyshelltest-0.8.1_1dev0-py3-none-any.whl
  • Upload date:
  • Size: 5.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.8.1_1dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 78e6ce10d2102ede568561e839ab9a9292b16a8482c4f8df1df14427587f4706
MD5 73948f8dfcc8fd57471b608a42c70545
BLAKE2b-256 959df318c0bb90dd4fd3fce3701a94b88c03022e274c0e1be0e0f4e56aec6396

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