Skip to main content

Test any command line interface in BDD manner.

Project description


Test any command line interface in BDD manner.

PyPI Build Status Coverage Status


A framework to easily test your command line interface in another(isolated) process and gather stdout, stderr and returnStatus of the process.


Only Python >= 3.6 is supported.

pip install bddcli



import sys

from bddcli import Given, when, stdout, status, stderr, Application, given

def foo():
    print(' '.join(sys.argv))
    return 0

app = Application('foo', 'mymodule:foo')

with Given(app, 'bar'):
    assert status == 0
    assert stdout == 'foo bar\n'

    when('Without any argument', given - 'bar')
    assert stdout == 'foo\n'

    when('Pass multiple arguments', 'bar baz')
    assert stdout == 'foo bar baz\n'

    when('Pass multiple arguments, another method', ['bar', 'baz'])
    assert stdout == 'foo bar baz\n'

    when('Add an argument', given + 'baz')
    assert stdout == 'foo bar baz\n'

Standard input

with Given(app, stdin='foo'):
    assert ...

    when('stdin is empty', stdin='')
    assert ...

Standard output and error

from bddcli import stderr, stdout

assert stderr == ... 
assert stdout == ... 

Environment variables

import os

from bddcli import Given, stdout, Application, when, given

def foo():
    e = os.environ.copy()
    del e['PWD']
    print(' '.join(f'{k}: {v}' for k, v in e.items()))

app = Application('foo', 'mymodule:foo')
with Given(app, environ={'bar': 'baz'}):
    assert stdout == 'bar: baz\n'

    when('Without any variable', environ=given - 'bar')
    assert stdout == '\n'

    when('Add another variables', environ=given + {'qux': 'quux'})
    assert stdout == 'bar: baz qux: quux\n'

See tests for more examples.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for bddcli, version 2.6.2
Filename, size File type Python version Upload date Hashes
Filename, size bddcli-2.6.2.tar.gz (8.0 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page