Lately I've been working in python. It is my first experience with the language and as part of the learning curve I should not only learn the nuts and bolts of the language but also research the tools I will use.
Lettuce is the tool I’ve chosen for BDD but it wasn’t easy to start working with it. I’ll share the steps necessary for a proper installation and configuration in a Windows environment.
These steps were performed in Windows 2003 server and I’m assuming that you have Python installed and configured as follows:
- easy_install, you can download it from http://pypi.python.org/pypi/setuptools
- Python folders added to your PATH environment, example: PATH=C:\Python26\Scripts;C:\Python26
The first issue appeared during the installation process. In lettuce’s website they use the pip command but I was unable to run lettuce after using this so I decided to try easy_install which worked for me:
After the installation, if you try to run lettuce in your command prompt you will see that lettuce is not found.
This happens because the lettuce file is not an executable, therefore you need to tweak this a little bit.
The lettuce file has no extension and is located in the Scripts folder of your python installation, in my case the file is in the folder C:\Python26\Scripts.
Because in Windows any .py file will be executed using the python interpreter, a quick fix could be to add that extension to the file, and then call lettuce using the extension instead.
After this you will see that the file is executed but an error is reported.
This happens because after renaming the file to lettuce.py python will use "lettuce" as a module name, hiding another lettuce module needed for a proper execution. A fix for this problem is to rename this file to something else, for instance:
Great! We don't have errors any more, lettuce is running but, what just happening here with these weird characters?
Note: If adding the python extension is an issue for you, you can create an .exe from your .py file. Windows will be able to find it and execute it. I recommend the exemaker tool which is pretty simple to use.
3. Fixing the Output
Lettuce is using colors in the output and is implemented by sending ANSI escape characters to the terminal, a feature that works in Unix and Mac, but not in Windows.
Fortunately there is a Python package that allows us to translate those ANSI escape characters into colors, colorama. First you need to install it:
When the installation finishes you have to tell colorama to translate lettuce’s output. We will do this by modifying the lettuce package initializer __init__.py. In my case this file is located in the folder: C:\Python26\Lib\site-packages\lettuce-0.1.15-py2.6.egg\lettuceAdd the following code after the latest import clause:
This is how the modification looks
After this change, run lettuce again and you will see the colored output.
Post a Comment