Recipe 39Test Python Code Using Lettuce

Problem

You want to test a Python app from Cucumber; for consistency’s sake, you want as much of your test code as possible to be in Python.

Ingredients

  • Lettuce for testing Python using a Cucumber-like syntax[259]

  • virtualenv for installing a Python sandbox to play in[260]

  • colorama for viewing pass/fail results in color on Windows[261]

Solution

There are a few different ways to drive Python code in plain English, each with its own set of trade-offs. Lettuce is a test framework that strikes a careful balance: it’s written in pure Python (so you won’t have to install extra dependencies to use it) but understands basic Gherkin syntax (so you can write similar tests to the ones you’d use in Cucumber). ...

Get Cucumber Recipes now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.