Lettuce tests with Python: make lettuce print to stdout

The lettuce BDD framework swallows the output of your steps if they try to print to stdout, so you will never see the output of the print in a step like this:

 
@step('Cell number (\d+) should (read|contain) "([^"]*)"')
def cell_group1_should_read_or_contain_group2(step, cell_number, read_or_contain, expected_text):
# your test logic here
print "somevar is now=" + some_var
assert_true(step, 15 == some_other_var)

If you need to print the variable during test development, e.g., because it contains the innerHMTL of some complex element, you can force lettuce to print it by abusing an always failing assertion:

@step('Cell number (\d+) should (read|contain) "([^"]*)"')
def cell_group1_should_read_or_contain_group2(step, cell_number, read_or_contain, expected_text):
# your test logic here
assert True == False, "somevar is now=" + some_var
assert_true(step, 15 == some_other_var)

It’s maybe easiest to run lettuce on the command line for this, e.g.,

cd my_app/test/
lettuce features/my_tested_feature_123123.feature

Hope this helps.

Advertisements

About dfspspirit

PhD student in bioinformatics, interested in photography, level design, digital image manipulation, architecture and, of course, bioinformatics.
This entry was posted in IT and computers, Software Design and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s