Application test with Python

Multi-Mechanize is an open source framework for performance and load testing. It runs concurrent Python scripts to generate load (synthetic transactions) against a remote site or service. Test output reports are saved as HTML or JMeter-compatible XML.

I will use pip to install the package but you can download the source and install it manually:

($ pip install multi-mechanize
Downloading/unpacking multi-mechanize  
  Downloading multi-mechanize-1.2.0.tar.gz
    Running egg_info for package multi-mechanize

    Downloading/unpacking Mechanize (from multi-mechanize)
      Downloading mechanize-0.2.5.tar.gz (383kB): 383kB downloaded
        Running egg_info for package Mechanize

        Installing collected packages: multi-mechanize, Mechanize
          Running install for multi-mechanize

          Installing multimech-run script to /home/danilochilene/envs/
          Installing multimech-newproject script to /home/danilochilene/envs/
          Installing multimech-gridgui script to /home/danilochilene/envs/

          Running install for Mechanize

          Successfully installed multi-mechanize Mechanize
          Cleaning up...

Install matplotlib to generate graphics

danilochilene@undead:~$ sudo apt-get install python-matplotlib  

Create our test project

The name of our project will be weather since the goal of it is to check weather though a webservice:

danilochilene@undead:~$ multimech-newproject weather  
danilochilene@undead:~$ cd weather/  
danilochilene@undead:~/weather$ find .  

config.cfg config file, you can set your options here  
./test_scripts -> directory with your test scripts
./results -> results

Every new project you create come with a default script in testscripts/ you can use it as a template to create your own.

Below it's content

import random  
import time  
class Transaction(object):  
  def __init__(self):

def run(self):  
  r = random.uniform(1, 2)
  self.custom_timers['Example_Timer'] = r

if __name__ == '__main__':  
  trans = Transaction()
  print trans.custom_timers

Every test script must have a Transaction class.

We are going to use Suds here which is a lightweight SOAP python client for consuming Web Services. For more information about it please access

danilochilene@undead:~/weather$ sudo pip install suds  
[sudo] password for danilochilene:
Downloading/unpacking suds  
Downloading suds-0.4.tar.gz (104kB): 104kB downloaded  
Running egg_info for package suds

Installing collected packages: suds  
Running install for suds  
/usr/bin/python -O /tmp/
removing /tmp/

Successfully installed suds  
Cleaning up...  

Below our test script that checks the weather using the webservice

Keep in mind that the webservice isn't real it just returns random results like: Rain, Sunny, Clooudy, etc. The main idea is just use it for testing purposes.

danilochilene@undead:~/weather/test_scripts$ cat  
#!/usr/bin/env python
from suds.client import *

class Transaction(object):  
def run(city):  
city = 'New York'  
url = ''  
client = Client(url)  
result = client.service.GetWeather(city)  
print result

if __name__ =='__main__':  
trans = Transaction()  

Lets run it to check if it's working:

danilochilene@undead:~/weather/test_scripts$ python  

Remove the default script since we are not going to use it:

danilochilene@undead:~/weather/test_scripts$ rm -f  

Edit the file config.cfg inside the directory weather to match below:

run_time = 30  
rampup = 0  
results_ts_interval = 10  
progress_bar = on  
console_logging = off  
xml_report = on

threads = 3  
script =  

Lets run the test

danilochilene@undead:~$ multimech-run weather

user_groups: 1  
threads: 3

[================100%==================] 30s/30s transactions: 224 timers: 0 errors: 0

analyzing results...

transactions: 227  
errors: 0

test start: 2013-05-18 19:48:47  
test finish: 2013-05-18 19:49:16

created: ./weather/results/results_2013.05.18_19.48.46/results.html

created: ./weather/results/results_2013.05.18_19.48.46/results.jtl  
created: last_results.jtl  

It worked. :)

Lets take a look at the results:

In case of any error you can activate the option console_logging at config.cfg.

Multi-mechanize is a powerfull and yet simple framework to performance test, for more information access

If you have any questions feel encouraged to comment. :)